Best practices forward-declaring QStringList (and other containers) in Qt6?
Solved
General and Desktop
-
Hi,
QtService from qt-solutions (https://code.qt.io/cgit/qt-solutions/qt-solutions.git/) does not build with Qt6:
In file included from ../src/qtservice_unix.cpp:4: ../src/qtservice.h:25:7: error: using typedef-name ‘using QStringList = class QList<QString>’ after ‘class’ 25 | class QStringList; | ^~~~~~~~~~~ In file included from /home/vincas/Qt/6.8.3/gcc_64/include/QtCore/qtypeinfo.h:9, from /home/vincas/Qt/6.8.3/gcc_64/include/QtCore/qglobal.h:47, from /home/vincas/Qt/6.8.3/gcc_64/include/QtCore/qcoreapplication.h:7, from /home/vincas/Qt/6.8.3/gcc_64/include/QtCore/QCoreApplication:1, from ../src/qtservice.h:7: /home/vincas/Qt/6.8.3/gcc_64/include/QtCore/qcontainerfwd.h:40:7: note: ‘using QStringList = class QList<QString>’ has a previous declaration here 40 | using QStringList = QList<QString>; | ^~~~~~~~~~~
In Qt6,
QStringList
is an alias, not a class, and soclass QStringList
errors out in https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice/src/qtservice.h?id=777e95ba69952f11eaec0adfb0cb987fabcdecb3#n25 .What would be the "best practices" way to handle this? I could:
- include
QtCore/qcontainerfwd.h
. Too-"implementation-detail"? - just include
#include <QStringList>
. Too-user-heavy? - do not include anything, as it seems
QtCore/qcontainerfwd.h
is already available via other Qt includes. Might break in the future? - ???
And to make it work on both Qt5 and Qt6, I might need to:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include <QtCore/qcontainerfwd.h> #else class QStringList; // Forward declaration only valid in Qt5 #endif
Which kinda feels overkill... so maybe just
#include <QStringList>
?What do you think?
Thanks!
P.S. I might try to push it via gerrit.
- include
-
Include QStringList header
-
T Talkless has marked this topic as solved