开始第一个QT GUI程序
1.在QT Createtor新建空项目
2.新建cpp文件#include<QApplication>
#include<QWidget> #include<QPushButton> #include <QTextCodec> //应用程序抽象类,窗口类,按钮类,按钮从属于窗口 int main(int argc,char *argv[]){ QApplication app(argc,argv); QWidget w; QPushButton button;
//设置窗口标题 w.setWindowTitle("欢迎");
//设置按钮名称 button.setText("按钮");
//将按钮对象放置在父窗口对象 button.setParent(&w); // button.show();
//设置按钮对象的位置 button.setGeometry(30,30,200,100);
//信号和槽 QObject::connect(&button,SIGNAL(clicked(bool)),&w,SLOT(close()));
//显示窗口 w.show(); // 循环消息 return app.exec(); }
注意:需要在以pro为后缀的文件加上一句话:
//导入相关资源
QT +=widgets gui

浙公网安备 33010602011771号