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. Problem when using Qt 6.2.2 with QgsApplication

Problem when using Qt 6.2.2 with QgsApplication

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.5k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    korai
    wrote on last edited by korai
    #1

    I want to move my QgsApplication to Qt6 from Qt5 but I have errors with compilation.

    In mainwindow.h file:

    class MainWindow : public QMainWindow, private Ui::MainWindowBase
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 );
        ~MainWindow();
    

    In mainwindow.cpp file:

    MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl)
        : QMainWindow(parent,fl)
    {
    ...
    }
    

    In main.cpp file:
    int main(int argc, char **argv)

    {
        // Start the Application
        QgsApplication app(argc, argv, true);
    
        MainWindow * mypMainWindow = new MainWindow();
        mypMainWindow->show();
        // Start the Application Event Loop
        return app.exec();
    }
    

    This structure works with Qt5. When I changed to Qt 6, I get the following errors. How should I change my code to be able to use Qt 6.2.2? I tried to fix it according to errors but it didn't work. Any comment/help is appreciated. Thank you.

    Error1:
    mainwindow.h:32: Fehler: no viable conversion from 'int' to 'Qt::WindowFlags' (aka 'QFlagsQt::WindowType')
    In file included from ../qgis_template/main.cpp:4:
    ../qgis_template/mainwindow.h:32:53: error: no viable conversion from 'int' to 'Qt::WindowFlags' (aka 'QFlagsQt::WindowType')
    MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 );
    ^ ~
    ../../../Applications/Qt/6.2.2/gcc_64/include/QtCore/qflags.h:87:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const QFlagsQt::WindowType &' for 1st argument
    class QFlags
    ^
    ../../../Applications/Qt/6.2.2/gcc_64/include/QtCore/qflags.h:87:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'QFlagsQt::WindowType &&' for 1st argument
    ../../../Applications/Qt/6.2.2/gcc_64/include/QtCore/qflags.h:109:33: note: candidate constructor not viable: no known conversion from 'int' to 'Qt::WindowType' for 1st argument
    constexpr inline Q_IMPLICIT QFlags(Enum flags) noexcept : i(Int(flags)) {}
    ^
    ../../../Applications/Qt/6.2.2/gcc_64/include/QtCore/qflags.h:110:33: note: candidate constructor not viable: no known conversion from 'int' to 'QFlag' for 1st argument
    constexpr inline Q_IMPLICIT QFlags(QFlag flag) noexcept : i(flag) {}
    ^
    ../../../Applications/Qt/6.2.2/gcc_64/include/QtCore/qflags.h:112:22: note: candidate constructor not viable: no known conversion from 'int' to 'std::initializer_list<WindowType>' for 1st argument
    constexpr inline QFlags(std::initializer_list<Enum> flags) noexcept
    ^
    ../qgis_template/mainwindow.h:32:53: note: passing argument to parameter 'fl' here
    MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 );
    ^
    Error 2:
    mainwindow.h:32: Fehler: missing default argument on parameter 'fl'
    ../qgis_template/mainwindow.h:32:53: error: missing default argument on parameter 'fl'
    MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 );
    ^

    Error3:
    main.cpp:18: Fehler: no matching constructor for initialization of 'MainWindow'
    ../qgis_template/main.cpp:18:38: error: no matching constructor for initialization of 'MainWindow'
    MainWindow * mypMainWindow = new MainWindow();
    ^
    ../qgis_template/mainwindow.h:27:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
    class MainWindow : public QMainWindow, private Ui::MainWindowBase
    ^
    ../qgis_template/mainwindow.h:32:5: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
    MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 );
    ^

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      @korai said in Problem when using Qt 6.2.2 with QgsApplication:

      public:
      MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 );

      Change your constructor to this (the same constructor signature defaults as QMainWindow):

      MainWindow(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
      
      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Qt::Flags is now stronger typed - it can no longer be initialized with an integer. You have to initialize it with an enum or empty with Qt::WindowFlags() or {} as you can see in the documentation:

        QMainWindow::QMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
        

        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
        2
        • K Offline
          K Offline
          korai
          wrote on last edited by korai
          #4

          Thank you @mchinand and @Christian-Ehrlicher for your answers.

          That problem has been solved, and I have another problem now.

          /usr/bin/ld: main.o: in function `__cxx_global_var_init.8':
          /home/unibw/dev/cpp/QGIS-Debug-Build/../QGIS/src/core/qgsapplication.h:1020: undefined reference to `QgsSettingsEntryStringList::QgsSettingsEntryStringList(QString const&, QgsSettings::Section, QList<QString> const&, QString const&)'
          /usr/bin/ld: mainwindow.o: in function `__cxx_global_var_init.8':
          
          /home/unibw/dev/cpp/QGIS-Debug-Build/../QGIS/src/core/qgsapplication.h:1020: undefined reference to `QgsSettingsEntryStringList::QgsSettingsEntryStringList(QString const&, QgsSettings::Section, QList<QString> const&, QString const&)'
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          make: *** [Makefile:320: Cpp_GUI] Error 1
          

          and the line 1020 in qgsapplication.h is :
          https://qgis.org/api/qgsapplication_8h_source.html#l01020

          The error comes from the library file. I looked at issues on QGIS Github but couldn't see this error. Do you have an idea about this?

          1 Reply Last reply
          0

          • Login

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