Find the answer to your Linux question:
Results 1 to 4 of 4
Hello Friends, I'm learning Qt 4 and I tried to compile a simple 'Hello Qt' program but the compiler gives error even though the source code is correct. Please help ...
  1. #1
    Just Joined! seeplusplus's Avatar
    Join Date
    Jan 2008
    Posts
    13

    Question Compiling Qt 4 program in Fedora 9

    Hello Friends,

    I'm learning Qt 4 and I tried to compile a simple 'Hello Qt' program but the compiler gives error even though the source code is correct.
    Please help me out of this.

    My program source code is:
    hello.cpp

    Code:
    #include <QApplication>
    
    #include <QLabel>
    
    int main(int argc, char *argv[])
    
    {
    
        QApplication app(argc, argv);
    
        QLabel *label = new QLabel("Hello Qt!");
    
        label->show();
    
        return app.exec();
    
    }

    and after qmake -project and qmake hello.pro, the make gives the following warning:
    Code:
    hello.cpp:1:24: error: QApplication: No such file or directory
    hello.cpp:2:18: error: QLabel: No such file or directory
    hello.cpp: In function ‘int main(int, char**)’:
    hello.cpp:5: error: ‘QApplication’ was not declared in this scope
    hello.cpp:5: error: expected `;' before ‘app’
    hello.cpp:6: error: ‘QLabel’ was not declared in this scope
    hello.cpp:6: error: ‘label’ was not declared in this scope
    hello.cpp:6: error: expected type-specifier before ‘QLabel’
    hello.cpp:6: error: expected `;' before ‘QLabel’
    hello.cpp:8: error: ‘app’ was not declared in this scope
    hello.cpp: At global scope:
    hello.cpp:3: warning: unused parameter ‘argc’
    hello.cpp:3: warning: unused parameter ‘argv’
    make: *** [hello.o] Error 1

    What should I do?

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    you are including the wrong files.

    instead of
    Code:
    #include <QApplication>
    #include <QLabel>
    do
    Code:
    #include <qapplication.h>
    #include <qlabel.h>
    Linux and me it's a love story

  3. #3
    Just Joined! seeplusplus's Avatar
    Join Date
    Jan 2008
    Posts
    13
    I want to use Qt 4. The solution you suggested is for Qt 3 users...


    Please help me compile with Qt 4.

  4. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    sorry i havent used qt4.

    but try to use
    Code:
    /usr/bin/qmake-qt4 -project
    /usr/bin/qmake-qt4
    make
    Linux and me it's a love story

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...