QT的第一个程序HELLO WORLD

1.打开VS2010新建一个QT的dialog类型程序

2.将框架生成的main.cpp代码修改如下:

#include "qthelloworld.h"
#include <QApplication>

int main(int argc, char *argv[])
{
 QApplication a(argc, argv);
 QTHelloworld w;
 w.show();
 return a.exec();
}

3.qthelloworld.h文件:

#ifndef QTHELLOWORLD_H
#define QTHELLOWORLD_H

#include <QApplication>
#include <QtGUI>

class QTHelloworld : public QMainWindow
{
 Q_OBJECT

public:
 QTHelloworld(QWidget *parent = 0, Qt::WFlags flags = 0);
 ~QTHelloworld();

private:
 Ui::QTHelloworldClass ui;
};

#endif // QTHELLOWORLD_H

4.qthelloworld.cpp文件:

#include "qthelloworld.h"

QTHelloworld::QTHelloworld(QWidget *parent, Qt::WFlags flags)
 : QMainWindow(parent, flags)
{
 ui.setupUi(this);
}

QTHelloworld::~QTHelloworld()
{

}

原文地址:https://www.cnblogs.com/djcsch2001/p/2009871.html