7.
下面我们以《C++ GUI Qt 4 编程(第二版)》【下载见 http://www.linuxidc.com/Linux/2012-06/61979.htm 】一书的第一章的三个例子,介绍一下Qt编程(代码和Qt的helloworld自带的代码有较大出入,我还需要好好研究研究):
为了方便,我们不新建工程了,就在Hello World的main.cpp中修改:
第一个例子:hello
将main.cpp修改如下:
- #include <QApplication>
- #include <QLabel>
程序很简单,就是显示一个Label
模拟器中的运行结果:

桌面运行结果:

第二个例子:quit
将main.cpp修改如下:
- #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();
- }
