Problem when using Qt 6.2.2 with QgsApplication
-
wrote on 1 Feb 2022, 17:52 last edited by korai 2 Jan 2022, 17:55
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 );
^ -
wrote on 1 Feb 2022, 18:14 last edited by
@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());
-
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())
-
wrote on 8 Feb 2022, 08:47 last edited by korai 2 Aug 2022, 08:48
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#l01020The 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/4