开发者

how to compile Qt code in command line on Mac OS

开发者 https://www.devze.com 2023-02-16 04:11 出处:网络
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.

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)开发者_StackOverflow中文版;

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

I tried to compile it but failed. "

‘QApplication’ was not declared in this scope "

How can I fix it?


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消