【QT5】 第一个hello world 程序

#include <QApplication>

#include <QWidget>
#include <QPushButton>

int main(int argc,char* argv[]){
    QApplication app(argc,argv);
    QWidget w;

    QPushButton button;
    button.setText("Button");
    button.setParent(&w);

    QObject::connect(&button,SIGNAL(clicked()),&w,SLOT(close()));

    w.setWindowTitle("hello world");
    w.show();
    return app.exec();
}

想要使用 QWidget 必须在.pro 文件中 添加QT +=widgets gui

这里w表示主窗口。

posted @ 2018-08-29 21:01  金舰  阅读(145)  评论(0编辑  收藏  举报