PDA

View Full Version : QT4 in Leopard: error: QApplication: No such file or directory




emil.s
Nov 23, 2007, 06:23 AM
I'm trying to learn QT4. But it seems as i can't compile any program...
I'm following this very basic guide:
http://doc.trolltech.com/4.0/tutorial-t1.html

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:
http://trolltech.com/developer/downloads/qt/mac

But i still get these errors! How do i get rid off them?



Cromulent
Nov 23, 2007, 07:06 AM
Are the headers / libraries in the correct place? Are you using the correct compiler options?

emil.s
Nov 23, 2007, 10:52 AM
Are the headers / libraries in the correct place? Are you using the correct compiler options?

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

/Library/Frameworks/QtGui.framework/Versions/4/Headers/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?

simon-says
Nov 25, 2007, 11:16 PM
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.

emil.s
Nov 27, 2007, 11:02 AM
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.

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! :)

simon-says
Nov 27, 2007, 01:49 PM
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.

emil.s
Nov 27, 2007, 02:38 PM
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.

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?

simon-says
Nov 27, 2007, 02:55 PM
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.

emil.s
Nov 27, 2007, 03:04 PM
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.

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. ;)

simon-says
Nov 27, 2007, 03:12 PM
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