C++ 将在QtCreator中创建的自定义小部件添加到主窗口
在我的主窗口中,我希望显示我使用QtCreator单独创建的小部件。以下是我迄今为止所做的工作C++ 将在QtCreator中创建的自定义小部件添加到主窗口,c++,qt,qt5,qt-creator,C++,Qt,Qt5,Qt Creator,在我的主窗口中,我希望显示我使用QtCreator单独创建的小部件。以下是我迄今为止所做的工作 为我的自定义小部件添加了一个新的Qt表单和类 在我的主窗口头文件中声明了新的小部件对象 试图将其添加到中心小部件。有错误 moopsbilling.cpp:10:错误:C2027:使用未定义的类型“QLayout” 我希望向主窗口添加几个其他自定义小部件,它们将是分页表单的一部分。但在这里,我遇到了一个错误,将它们添加到中心小部件中 我希望有人能指导,如何解决这个问题,以及我如何在我的主窗体中添加(
\include
或\include
?
#include <QMainWindow>
#include "newcustomerwidget.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MoopsBilling; }
QT_END_NAMESPACE
class MoopsBilling : public QMainWindow
{
Q_OBJECT
public:
MoopsBilling(QWidget *parent = nullptr);
~MoopsBilling();
private:
Ui::MoopsBilling *ui;
NewCustomerWidget *newCustomerWidget; // this is the new widget
};
MoopsBilling::MoopsBilling(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MoopsBilling)
{
ui->setupUi(this);
newCustomerWidget = new NewCustomerWidget();
ui->centralwidget->layout()->addWidget(newCustomerWidget); // adding this to central widget gives me error (line 10)
}