且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

QT的第一个程序HELLO WORLD

更新时间:2022-08-18 20:03:29

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()
{

}