QT4 in Leopard: error: QApplication: No such file or directory

Discussion in 'Mac Programming' started by emil.s, Nov 23, 2007.

  1. macrumors newbie

    I'm trying to learn QT4. But it seems as i can't compile any program...
    I'm following this very basic guide:

    But when i try to compile it i get:
    emil@MacBooken.local: ~/Desktop $ g++ QT-hello.cpp 
    QT-hello.cpp:1:24: error: QApplication: No such file or directory
    QT-hello.cpp:2:23: error: QPushButton: No such file or directory
    QT-hello.cpp: In function 'int main(int, char**)':
    QT-hello.cpp:6: error: 'QApplication' was not declared in this scope
    QT-hello.cpp:6: error: expected `;' before 'app'
    QT-hello.cpp:8: error: 'QPushButton' was not declared in this scope
    QT-hello.cpp:8: error: expected `;' before 'hello'
    QT-hello.cpp:9: error: 'hello' was not declared in this scope
    QT-hello.cpp:12: error: 'app' was not declared in this scope
    I know i got these errors in GNU/Linux when i tried to compile some programs some time ago, but the errors where gone after i installed some dev-libs.

    Now, in OS X i have installed "qt-mac-opensource-4.3.2.dmg" from:

    But i still get these errors! How do i get rid off them?
  2. macrumors 603


    Are the headers / libraries in the correct place? Are you using the correct compiler options?
  3. macrumors newbie

    Hi! This is what "locate" fount when searching for "QApplication"


    And i'm trying to compile it with just "g++ ./file-name.cpp".
    I think i should use the "-l" or "-L" option, but with what parameters?
  4. macrumors regular

    The problem here is that you are just trying to straight compile with gcc. If you read further down in the article you will see that you need to run qmake to build a project file first.

    In the directory you created your .cpp file, run the command 'qmake -project' to generate a .pro project file. After that run 'qmake', this will generate a Makefile. Then just run 'make'. Your program will then be built and you can run it.

    After you create your Qt project file, you can use 'qmake -spec macx-xcode', this will create you an xcode project for you. This is handy so you don't have to stay in the command line.
  5. macrumors newbie

    Hi! Worked fine, until i tried with "make". And of course it doesn't work, there is no makefile...

    emil@MacBooken.local: ~/Desktop/QT-test $ ls
    Info.plist		QT-hello.cpp		QT-test.pro		QT-test.xcodeproj
    I have tried with both "qmake -project" and "qmake -project ./QT-hello.cpp".
    The "qmake" command gives nothing.

    Thanks for helping! :)
  6. macrumors regular

    Ah, the Qt-Test.xcodeproj is an XCode project you can use. Your default for qmake must be for it to build an XCode project. I always build Qt from source and the default is makefiles. If after you create the Qt project file with 'qmake -project' you run 'qmake -makefile' this will generate you a makefile that you can run make with.
  7. macrumors newbie

    Unfortunately not:
    emil@MacBooken.local: ~/Desktop/QT-test $ qmake -project
    emil@MacBooken.local: ~/Desktop/QT-test $ qmake -makefile
    emil@MacBooken.local: ~/Desktop/QT-test $ ls
    Info.plist		QT-hello.cpp		QT-test.pro		QT-test.xcodeproj
    But the Xcode project worked fine. :) "Hello World!" :D
    But i prefer the commandline when i edit the code with "vim" anyway...

    Anymore proposals?
  8. macrumors regular

    Hmm that is interesting that it generate a makefile for you, normally if qmake is called and does nothing it will display the help if anything. You might be able to try 'qmake -spec macx-g++'. I hear you about Vim, though most of the time I prefer the nice interface of XCode. Especially when dealing with projects that have 80+ source files.
  9. macrumors newbie

    Yes! Worked great, thanks! :)

    And of course an IDE is better with such large projects. But vim is perfect for just edit some single files. ;)
  10. macrumors regular

    Cool. No problem for the help. I work with Qt daily, I know it's good and bad things. If you want to pick up a book relating to Qt Programming, I can recommend one.

    C++ GUI Programming with Qt 4
    Jasmin Blanchette and Mark Summerfield
    ISBN: 0131872494

    I have looked at a few, and that was the most helpful to start out with. There are a few other new ones I need to check out.

    - Brent Nycum

Share This Page