Cannot Compile Code...
-
Hi!
I am back to C++ and Qt after some time and want to run the
code found in "C++ GUI Programming with Qt 4" book.
I have downloaded and installed Qt 5.11.1 for x86, and MINGW 32-bit.I get these errors when runing the code:
These are my debug settings:
Here is the code:
#include <QCoreApplication> #include <QtWidgets/QLabel> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QLabel *label = new QLabel("Hello Qt!"); label->show(); return a.exec(); }
-
Hi
Most likely the pro file is old.
make sure you have
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -
Hi,
In addition to the correct answer of @mrjj, your application won’t work. You need a QApplication if you want to use widgets.
Just as a note
You can find updated version of the code here
https://github.com/mutse/qt5-book-code
That should be easier to use in Qt5 -
Hi
Most likely the pro file is old.
make sure you have
greaterThan(QT_MAJOR_VERSION, 4): QT += widgetsHi. I have placed
QT += widgets
at the second line of .pro file.
Now code compiles ok but as SGaist mentioned I need a QApplication.
Here is my corrected code:
-
Super.
There is some difference with the includes between 4 and 5.