qt for linux (红帽) 终端编译

来源:互联网 发布:云控软件 编辑:程序博客网 时间:2024/04/28 17:47

(一)  如何编译连接使用QT

1)        [root@kuenkingQtTest]# ls

QtTest1.cpp

[root@kuenking QtTest]#

2)        [root@kuenkingQtTest]# qmake-qt4 -project

QFileInfo::absolutePath: Constructedwith empty filename

[root@kuenking QtTest]# ls

QtTest1.cpp  QtTest.pro

[root@kuenking QtTest]#

3)        [root@kuenkingQtTest]# qmake-qt4 -makefile

[root@kuenking QtTest]# ls

Makefile  QtTest1.cpp QtTest.pro

[root@kuenking QtTest]#

在没有错误的前提下:执行make,如第四步

4)        [root@kuenkingQtTest]# make

g++ -c -pipe -O2 -g -pipe -Wall-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32-march=i686 -mtune=atom -fasynchronous-unwind-tables -Wall -W -D_REENTRANT-DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I.-I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -o QtTest1.oQtTest1.cpp

g++ -Wl,-O1 -o QtTest QtTest1.o     -lQtGui -lQtCore -lpthread

[root@kuenking QtTest]# ls

Makefile QtTest  QtTest1.cpp  QtTest1.o QtTest.pro

[root@kuenking QtTest]#

5)        到这步就可以了。然后执行QtTest就会显示界面了:如下面所示:

6)        [root@kuenkingQtTest]# ./QtTest

7)  

8)        这个测试的代码如下:

#include <qapplication.h>

#include <qlabel.h>

#include <qstring.h>

 

int main(int argc,char **argv)

{

       QApplication app(argc,argv);

        QLabel*label = new QLabel(NULL);

        QStringstring("hksd");

       label->setText(string);

//      label->ALignment(QT::AlignVCenter|QT::AlignHCenter);

       label->setGeometry(0,0,180,75);

//     app.setMainWidget(label);

       label->show();

        returnapp.exec();

 

}

0 0
原创粉丝点击