【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表示主窗口。

猜你喜欢

转载自www.cnblogs.com/tao-zhu-forever/p/9556809.html