Closed Vekhir closed 1 week ago
Closing until 6.8 gets released, because this might just be a mistake on Qt's part, because the documentation still says that there should be a constructor QChar(int), which is missing in the beta leading to this error.
Further investigation revealed that the constructor QChar(int)
still exists (as documented), but is only callable with an explicitly typed
but can only be called explicitly, not allowing implicit conversions anymore. The macro int
, not an implicitly typed hex-literal
(which gets treated as an int
in most circumstances). This change is not clearly reflected in the documentation, which is why I missed it at first.QT_IMPLICIT_QCHAR_CONSTRUCTION
, used by OpenBoard and allowing these conversions, gets removed.
Final post-mortem: The macro QT_IMPLICIT_QCHAR_CONSTRUCTION
gets removed, so we have to explicitly construct a QChar from the literals. The macro allowed implicit conversions to ease the transition from Qt5 (with implicit conversions from integer types) to Qt6 (which by default requires explicit construction with integer types).
This is solved with the merging of the related PR.
Describe the problem While checking for versions to reproduce bugs (or see if they are resolved), I also checked the current 6.8.0beta3 (in kde-unstable). This failed to build with
error: conversion from ‘int’ to ‘QChar’ is ambiguous
in several places.KEYBT
takes in a QChar (see here), while the declaration ofKEYBTDECL
is used with ahex-literal
(see here), requiring an implicit conversion fromint
toQChar
. Every invocation ofKEYBT
is affected, totaling 240 calls in the Linux code and another 236 in the Windows code.I expect this behaviour to be also in 6.8.0.
Investigation The issue stems from the removal of the
QT_IMPLICIT_QCHAR_CONSTRUCTION
macro (which is used in both Linux and Windows versions): qt/qtbase@54f222. This means that aQChar
can only be constructed explicitly from anint
, whereas before (in Qt5, and Qt6 with the macro), an implicit conversion was allowed. Since 6.0, most constructors taking integers are explicit "to avoid dangerous mistakes when accidentally mixing integral types and strings." Until 6.8, this behaviour could be disabled viaQT_IMPLICIT_QCHAR_CONSTRUCTION
, but not anymore.Versions Provide version information for all components and libraries.
dev
Build commands I'm using the
cmake
community build for Arch Linux, thoughqmake
should be similarly affected. Full instructions: PKGBUILDError messages There is a much clearer error at the beginning:
It refers to qt/qtbase:src/corelib/text/qchar.h. The errors if the macro is removed look like this:
Suggestions, solutions ~~Since it's a preprocessor directive, there isn't much typing, though it might be possible to
static_cast
theint
tochar
or something. To keep the current behaviour, an explicit cast (usingstatic_cast<int>()
or similar) might be the best approach.~~ Explicitly call the QChar constructorQChar(...)
instead of relying on C++ conversions.