Cannot compile code against qt4



  • Hello, I'm running ArchLinux and recently installed Qt4 and Qt5. However, the tutorial that I'm going through requires Qt4.

    Here is my code.
    [code]#include <QApplication>
    #include <QWidget>

    int main(int argc, char * argv[])
    {
    QApplication app(argc, argv);

    QWidget window;

    window.resize(250, 150);
    window.setWindowTitle("Simple example");
    window.show();

    return app.exec();
    }[/code]

    I then did the following:
    [code]% qmake -project
    % qmake
    % make[/code]

    And this is what I got:
    [code]g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt/mkspecs/linux-g++ -I. -I. -I/usr/include/qt -I/usr/include/qt/QtGui -I/usr/include/qt/QtCore -I. -o hello_world.o hello_world.cpp
    hello_world.cpp:3:24: fatal error: QApplication: No such file or directory
    #include <QApplication>
    ^
    compilation terminated.
    Makefile:298: recipe for target 'hello_world.o' failed
    make: *** [hello_world.o] Error 1[/code]

    How do I point to the correct headers/libraries?



  • I got it! I used the tool qtchooser to run qmake so that when the Makefile is generated, it's generated with Qt4 in mind. The process was something like this:
    [code]qmake -project && qtchooser -run-tool=qmake -qt=4 && make[/code]


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should be able to go through the same tutorial using Qt 5 with some minor modifications like

    @QT += widgets@

    when using widgets in your application (the error you are currently getting using Qt 5's qmake)

    In between, and since you found a solution (thanks for sharing by the way) please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.