Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best practices forward-declaring QStringList (and other containers) in Qt6?
QtWS25 Last Chance

Best practices forward-declaring QStringList (and other containers) in Qt6?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 90 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • TalklessT Offline
    TalklessT Offline
    Talkless
    wrote last edited by
    #1

    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 so class 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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      Include QStringList header

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • TalklessT Talkless has marked this topic as solved

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved