qt程序入门
1.helloworld
qt是一个界面开发平台,可以用在windows,linux上,我在这里主要是用在
装有linux操作系统的嵌入式平台上,首先介绍入门程序helloworld:
#include <QApplication>
#include <QLabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QLabel *label=new QLabel("Hello Qt!");
label->show();
return app.exec();
}
每个qt程序必须有一个入口app,需要有一个主界面,所有的其他组件都是其子单元,
然后记得要调用该组件的show()函数让其显示在界面上,最后把控制权交给app,让其
执行。
2.button函数
就是实例化一个button,然后将其按下后发出的信号和app的退出槽联系到一起,显示
#include <QApplication>
#include <QPushButton>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QPushButton *button = new QPushButton("Quit");
QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));
button->show();
return app.exec();
}