按下“pushButton_2”后,我正在尝试在 MainWindow 的图层中显示小部件“widg”,但我收到此错误:“在 ')' 令牌之前预期的主表达式”
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "widg.h"
#include "ui_widg.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->pushButton_2, SIGNAL(clicked()), SLOT(slotPush2()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotPush2()
{
ui->verticalLayout_3->addWidget(widg);
}
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void slotPush2();
};
#endif // MAINWINDOW_H
widg.h
#ifndef WIDG_H
#define WIDG_H
#include <QWidget>
namespace Ui {
class widg;
}
class widg : public QWidget
{
Q_OBJECT
public:
explicit widg(QWidget *parent = 0);
~widg();
private:
Ui::widg *ui;
};
#endif // WIDG_H
widg.cpp
#include "widg.h"
#include "ui_widg.h"
widg::widg(QWidget *parent) :
QWidget(parent),
ui(new Ui::widg)
{
ui->setupUi(this);
}
widg::~widg()
{
delete ui;
}
请帮助我,我的错误是什么?