这个工程是在VS2008下建的
//Helloworld.h
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
#include <QtGui/QMainWindow>
#include "ui_helloworld.h"
class HelloWorld : public QMainWindow
{
Q_OBJECT
public:
HelloWorld(QWidget *parent = 0, Qt::WFlags flags = 0);
~HelloWorld();
private:
Ui::HelloWorldClass ui;
};
#endif // HELLOWORLD_H
//helloworld.cpp
#include "helloworld.h"
HelloWorld::HelloWorld(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}
HelloWorld::~HelloWorld()
{
}
//main.cpp
#include "helloworld.h"
#include <QtGui/QApplication>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// HelloWorld w;
// w.show();
QPushButton b("Close All");
b.show();
QObject::connect(&b, SIGNAL(clicked()), &a, SLOT(quit()));
QLabel l("Hello,world!");
// l.setAlignment(Qt::Alignment());
l.setAlignment(Qt::AlignCenter);
l.show();
return a.exec();
}
运行的效果如下:
Qt HelloWorld 示例
本文通过一个简单的Qt项目示例,展示了如何使用Qt库创建一个带有按钮和标签的基本窗口应用程序。该程序在Visual Studio 2008中构建,利用了Qt框架来实现GUI组件。

1162

被折叠的 条评论
为什么被折叠?



