Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt6: recent project paths are stored in QGIS.ini in UTF-8 (instead of hex-escaped Unicode), incompatible with Qt5 version #60088

Open
1 of 2 tasks
justinbb opened this issue Jan 9, 2025 · 8 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! macOS qt6 Windows Related to Windows operating system

Comments

@justinbb
Copy link
Contributor

justinbb commented Jan 9, 2025

What is the bug or the crash?

Using a Mac Qt6 build (thanks @m-kuhn!)
– the QGIS.ini file from regular (Qt5) releases is interpreted correctly
– but when it is written back out, recent project paths are encoded in UTF-8
The UTF-8 encoded QGIS.ini cannot be read correctly by Qt5 QGIS, which tries to interpret each octet of UTF-8 as if it were a separate Unicode character.
The UTF-8 QGIS.ini is (fortunately) interpreted correctly by Qt6 QGIS. Switching back and forth between Qt5 and Qt6 builds, however, leads to increasing problems.

Steps to reproduce the issue

  1. In a Qt5 QGIS, create a project and save it under a name containing a non-ASCII character, e.g. • (U+2022). Quit QGIS
  2. Examine QGIS.ini with a text editor. In the recentProjects section, find the newly saved project: its name will contain \x2022
  3. Now open Qt6 QGIS. Note the (correct) filename in the recent projects lists. Quit QGIS
  4. Examine QGIS.ini with a text editor. The project's name will have been rewritten in UTF-8, so it will display normally if the text editor is correctly interpreting UTF-8 text. The hex codes for the • character will be E2 80 A2.
  5. Open Qt5 QGIS. In the recent files list, the file is greyed out and its name is displayed incorrectly with three characters in place of the •, the Unicode code points U+00E2 U+0080 U+00A2. Quit QGIS
  6. Examine QGIS.ini with a text editor again, there will now be \xe2\x80\xa2, the misinterpretation is now hex-escaped and getting difficult to recover from.

Versions

QGIS version | 3.41.0-Master -- | -- QGIS code revision | 9f6d7bd   Libraries Qt version | 6.8.1 Python version | 3.11.10 GDAL/OGR version | 3.9.3 PROJ version | 9.5.1 EPSG Registry database version | v11.022 (2024-11-05) GEOS version | 3.13.0-CAPI-1.19.0 SQLite version | 3.47.2 PDAL version | 2.8.1 PostgreSQL client version | unknown SpatiaLite version | 5.1.0 QWT version | 6.3.0 QScintilla2 version | 2.14.1 OS version | macOS Sonoma (14.7)   Active Python plugins db_manager | 0.1.20 MetaSearch | 0.3.6 processing | 2.12.99

QGIS version
3.41.0-Master
QGIS code revision
9f6d7bd6

Libraries
Qt version
6.8.1
Python version
3.11.10
GDAL/OGR version
3.9.3
PROJ version
9.5.1
EPSG Registry database version
v11.022 (2024-11-05)
GEOS version
3.13.0-CAPI-1.19.0
SQLite version
3.47.2
PDAL version
2.8.1
PostgreSQL client version
unknown
SpatiaLite version
5.1.0
QWT version
6.3.0
QScintilla2 version
2.14.1
OS version
macOS Sonoma (14.7)

Active Python plugins
db_manager
0.1.20
MetaSearch
0.3.6
processing
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

Although this is not an issue if one sticks to Qt5 or Qt6, it makes switching back and forth difficult (unless one limits filenames to ASCII characters). Some sort of workaround would be helpful to avoid problems when the transition arrives.

@justinbb justinbb added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 9, 2025
@nicogodet nicogodet added the Windows Related to Windows operating system label Jan 9, 2025
@nicogodet
Copy link
Member

Issue valid for windows too

@nicogodet
Copy link
Member

Same for news feed

@justinbb
Copy link
Contributor Author

justinbb commented Jan 9, 2025

Thank you for the extra information confirming that Qt created the situation. A few years ago, in one of the final Qt5 releases, they should have made Qt5 capable of reading the new Qt6 format – it would have been easy to do and effective. Now it's up to applications such as QGIS to work around their dropped ball.

The Qt6 choice of using UTF-8 for the ini file is sound, as well as being the (already established) way of the future. The most appropriate fix would therefore be to add code in QGIS Qt5 builds to handle UTF-8 correctly if it is present in the ini file. (There is no ambiguity, as the Qt5 format uses only USASCII characters to do its custom hex encoding of Unicode.) It would be a wrapper around whatever Qt call is used to read the ini file. No need to do anything when writing the ini file, since the Qt5 format is read correctly by Qt6.

@justinbb
Copy link
Contributor Author

justinbb commented Jan 9, 2025

The job can probably be done (Qt5 builds only) with QSettings::setIniCodec("UTF-8"), called immediately after constructing a QSettings object. To be determined: can this call be used all the time (if it still allows hex-escaped Unicode to be read), or does one have to try to figure out which format is present and set the UTF-8 iniCodec only if necessary?
See

@justinbb
Copy link
Contributor Author

justinbb commented Jan 9, 2025

Note that it will also be necessary to insert QSettings::setIniCodec(nullptr) after reading / before any attempt is made to write the ini file, so that Qt5 builds continue to write the ini file in the old format.

@m-kuhn
Copy link
Member

m-kuhn commented Jan 9, 2025

We could also rename the ini file for qt6 builds (QGIS4.ini or QGIS-qt6.ini)

@justinbb
Copy link
Contributor Author

We could also rename the ini file for qt6 builds (QGIS4.ini or QGIS-qt6.ini)

QGIS4.ini would be more user-friendly, I think. This solution may be simpler (and acceptable to users as long as the old ini file is migrated).

Advantages of a pair of calls to QSettings::setIniCodec() as I described above, if that does the job:

  • elegant: restricted to Qt5 builds and therefore would disappear in the long term
  • no change in the ini filename

Disadvantages:

  • the problem would be solved only for people alternating between Qt6 and late Qt5 (i.e., after the patch); anyone opening a Qt6 ini with a current or older Qt5 build would provoke the issue
  • would need to be tried out (and I am not really in a position to do the pull request myself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! macOS qt6 Windows Related to Windows operating system
Projects
None yet
Development

No branches or pull requests

4 participants