[SOLVED] Problem with "Hello world" (undefinded reference)



  • Hi. I'm trying to learn QT and getting these (simple?) errors..

    My code for undefined.pro:
    @
    TEMPLATE = app
    TARGET = name_of_the_app

    QT = core gui
    
    SOURCES += \
    main.cpp
    

    @
    My code for main.cpp:
    @
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QPushButton>

    int main(int argc, char **argv)
    {
    QApplication app (argc, argv);
    QPushButton button ("Hello World");
    button.show();
    return app.exec();
    }
    @
    And these errors...
    @
    C:\Qt\Qt5.0.2\build-untitled-Desktop_Qt_5_0_2_MinGW_32bit-Debug\debug\main.o:-1: In function Z5qMainiPPc': C:\Qt\Qt5.0.2\untitled\main.cpp:6: Fehler:undefined reference to_imp___ZN12QApplicationC1ERiPPci'
    C:\Qt\Qt5.0.2\untitled\main.cpp:7: Fehler:undefined reference to _imp___ZN11QPushButtonC1ERK7QStringP7QWidget' C:\Qt\Qt5.0.2\untitled\main.cpp:8: Fehler:undefined reference to_imp___ZN7QWidget4showEv'
    C:\Qt\Qt5.0.2\untitled\main.cpp:9: Fehler:undefined reference to _imp___ZN12QApplication4execEv' C:\Qt\Qt5.0.2\untitled\main.cpp:9: Fehler:undefined reference to_imp___ZN11QPushButtonD1Ev'
    C:\Qt\Qt5.0.2\untitled\main.cpp:9: Fehler:undefined reference to _imp___ZN12QApplicationD1Ev' C:\Qt\Qt5.0.2\untitled\main.cpp:7: Fehler:undefined reference to_imp___ZN11QPushButtonD1Ev'
    C:\Qt\Qt5.0.2\untitled\main.cpp:9: Fehler:undefined reference to _imp___ZN11QPushButtonD1Ev' C:\Qt\Qt5.0.2\untitled\main.cpp:9: Fehler:undefined reference to_imp___ZN12QApplicationD1Ev'
    collect2.exe:-1: Fehler:error: ld returned 1 exit status
    @
    PS: I'm using QT Creator 5.0.2.. Any help please?

    [Edit: Added @ tags and reformatted text -- mlong]


  • Moderators

    You need to add widgets to your qmake's profile:
    @
    QT = core gui widgets
    @


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If you are using Qt5 you are missing widgets in your QT variable.

    As a side note it's Qt, QT stands for Apple's QuickTime.

    Hope it helps



  • Did it myself already, thanks anyway!


Log in to reply
 

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