Josh Morrison
Josh Morrison

Reputation: 7636

how to compile Qt code in command line on Mac OS

I download this : http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.2.dmg and install it. Then I got a Qt helloworld.cc.

 #include <QApplication>
 #include <QPushButton>

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

     QPushButton hello("Hello world!");
     hello.resize(100, 30);

     hello.show();
     return app.exec();
 }

I tried to compile it but failed. "

‘QApplication’ was not declared in this scope "

How can I fix it?

Upvotes: 2

Views: 5275

Answers (2)

ak.
ak.

Reputation: 3449

you can also do this (I hope I'm not wrong):

$ qmake -project
$ qmake
$ make

of course you should cd to your source file. Also, I think it's a good idea to stick to the *.cpp file naming when you work with Qt

Upvotes: 4

Carl Norum
Carl Norum

Reputation: 225142

It works here for me. You didn't show your command line, but it seems like you aren't passing the right flags to tell your compiler where the headers/frameworks are. Here's what I used:

g++ -I /Library/Frameworks/QtGui.framework/Versions/4/Headers \
    -o example example.cpp \
    -framework QtGui -framework QtCore

Upvotes: 3

Related Questions