方法一: 找到工具栏——选项——kits 方法二: 项目中的构建目录 方法三: 右击清楚,再编译
冷静,仔细(错误信息中找出问题),定位(debug),解决,记录 法记录
这里是让界面持续打开(死循环) 再#include“Widget.h”并打开,就能出现界面
#include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }只用修改这一部分 .cpp文件中
#include "hello.h" #include "ui_hello.h" Hello::Hello(QWidget *parent) : QWidget(parent), ui(new Ui::Hello) { ui->setupUi(this); } Hello::~Hello() { delete ui; }其余的做法,就与1,2相同
在头文件中声明:
#include <QPushButton> public: explicit Widget(QWidget *parent = 0); ~Widget(); private: Ui::Widget *ui; QPushButton *pushbutton1; QPushButton *pushbutton2; QPushButton *pushbutton3;public,private 都可以 但重点是*。 在不是main的.cpp文件中实例化:
//在文件开头,也要include<QHBoxLayout> pushbutton1 = new QPushButton(this); pushbutton1->setText("one"); pushbutton2 = new QPushButton(this); pushbutton2->setText("two"); pushbutton3 = new QPushButton(this); pushbutton3->setText("three"); //实例化水平格式 QHBoxLayout *hlayout = new QHBoxLayout; //放入格式中 hlayout->addWidget(pushbutton1); hlayout->addWidget(pushbutton2); hlayout->addWidget(pushbutton3); /输出格式 setLayout(hlayout);