这个工程是在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();
}
运行的效果如下: