kiwix-desktop icon indicating copy to clipboard operation
kiwix-desktop copied to clipboard

BugFix: Compilation Failure for Qt6 Due to Deprecated Members

Open ShaopengLin opened this issue 9 months ago • 1 comments

Fixes #1102

Tested on Qt 6.2.4.

src/contentmanagermodel.cpp:40:16: error: ‘class QVariant’ has no member named ‘type’; did you mean ‘typeId’?
   39 |         if ( r.type() == QVariant::ByteArray )
      |                ^~~~
      |                typeId
src/contentmanagermodel.cpp:40:36: error: ‘ByteArray’ is not a member of ‘QVariant’
   39 |         if ( r.type() == QVariant::ByteArray )
      |

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:

  • Added macro to make the application still compatible with Qt 5
  • Used equivalent new features from Qt 6 to replace the lines.

ShaopengLin avatar May 05 '24 22:05 ShaopengLin

I recommend we have compilation pipelines to check both Qt versions.

Yes, see #1103

kelson42 avatar May 06 '24 03:05 kelson42

@veloman-yunkan I found two ways for type checking for both Qt5 and 6:

  • r.typeName() == QMetaType(QMetaType::QByteArray).name()
  • r.userType() == QMetaType::QByteArray

:x: The typeName approach isn't something we want as string comparison is unnecessary overhead when we have ints.

:white_check_mark: The userType approach works well as it is:

  • Same as type() for non-user defined type in Qt5
  • Exact same behavior as typeId() in Qt6
  • The change commit also recommends using userType instead, which I will use in this commit.

I imagine in the future, they might decide to remove either typeId() or userType(). Since its 50/50 we can just use userType.

ShaopengLin avatar May 07 '24 15:05 ShaopengLin