-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
BugFix: Compilation Failure for Qt6 Due to Deprecated Members #1104
Conversation
Yes, see #1103 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe your change is the best way to fix the current problem. However I suspect that you don't know about src/portutils.h
. See if you can come up with a convenient and future-proof utility that can be used for portably checking the type of a QVariant
. If not, we will merge the PR as is.
src/contentmanagermodel.cpp
Outdated
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | ||
if ( r.type() == QVariant::ByteArray ) | ||
return r; | ||
#else | ||
if ( r.typeId() == QMetaType::QByteArray ) | ||
return r; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, in case there is no good way to move the conditional compilation into portutils.h
, I would like to restrict the conditional compilation to the least amount of code as follows:
const bool gotThumbnailData =
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
r.type() == QVariant::ByteArray;
#else
r.typeId() == QMetaType::QByteArray;
#endif
if ( gotThumbnailData )
return r;
Above can be turned into a more readable form if we introduce a special macro that will select during compile time the right expression depending on the version of Qt used:
const bool gotThumbnailData = QT5VS6(r.type() == QVariant::ByteArray,
r.typeId() == QMetaType::QByteArray);
if ( gotThumbnailData )
return r;
src/contentmanagermodel.cpp
Outdated
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | ||
if ( faviconEntry.type() == QVariant::ByteArray ) | ||
return faviconEntry; | ||
#else | ||
if ( faviconEntry.typeId() == QMetaType::QByteArray ) | ||
return faviconEntry; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
In case you wonder what the proposed change improves, it minimizes the amount of code duplication between the conditionally compiled pieces and hence the risk that, for whatever reasons, one of the branches is updated and the other is not.
@veloman-yunkan I found two ways for type checking for both Qt5 and 6:
❌ The typeName approach isn't something we want as string comparison is unnecessary overhead when we have ints. ✅ The userType approach works well as it is:
I imagine in the future, they might decide to remove either typeId() or userType(). Since its 50/50 we can just use userType. |
Replaced deprecated member type() and QVariant::Type to compatible members in both Qt5&6
2897df3
to
086ba67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
Fixes #1102
Tested on Qt 6.2.4.
QVariant.type() and QVariant::ByteArray has been deprecated. We will use the new function QVariant.typeId() and QMetaType::QByteArray from Qt6.
I recommend we have compilation pipelines to check both Qt versions.
Fix: