[英]Inheritance between class QLayout and class QMainWindow Qt c++
I have a MainWindow class that inherits from QMainWindow. 我有一个从QMainWindow继承的MainWindow类。 I have another LayoutWindow class that inherits from QLayout.
我有另一个从QLayout继承的LayoutWindow类。 When I declare an instance of the LayoutWindow class, I have an error:
当我声明LayoutWindow类的实例时,出现错误:
error: invalid new-expression of abstract class type ...
错误:抽象类类型的无效new表达式...
I do not understand because QMainWindow inherits from QWidget which inherits from QLayout? 我不明白,因为QMainWindow继承自QWidget,而QWidget继承自QLayout?
Here is my code : 这是我的代码:
Class MainWindow : 类MainWindow:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{//instance class LayoutWindow
layoutwindow=new LayoutWindow();
centralArea = new QWidget;
centralArea->setLayout(layoutwindow);
setCentralWidget(centralArea);
}
Class LayoutWindow.h 类LayoutWindow.h
class LayoutWindow : public QLayout{
Q_OBJECT
public:
LayoutWindow();
};
class LayoutWindow.cpp LayoutWindow.cpp类
LayoutWindow::LayoutWindow(){
//here is my code
}
Would anyone have some idea of my problem? 有人会知道我的问题吗?
QLayout
has pure virtual methods, you have to implement these in a subclass you wish to instantiate. QLayout
具有纯虚拟方法,您必须在要实例化的子类中实现这些方法。
These are 这些是
void addItem(QLayoutItem *item);
int count() const;
QLayoutItem * itemAt(int index) const;
QLayoutItem * takeAt(int index);
Your assertion that QWidget
inherits QLayout
is false, it inherits from QObject
and QPaintDevice
, both of which have no base classes. 您关于
QWidget
继承QLayout
断言是错误的,它继承自QObject
和QPaintDevice
,这两个都没有基类。 QWidget
has a layout member , which arranges child widgets. QWidget
具有一个layout 成员 ,该成员可安排子窗口小部件。
I also don't think that you need a class that derives from QLayout
. 我也认为您不需要从
QLayout
派生的类。 You should instead use a combination of objects of existing layout and widget types to arrange your window. 相反,您应该结合使用现有布局和窗口小部件类型的对象来排列窗口。 You should have, as part of the QT install, a tool for visually designing windows,
QDesigner.exe
. 作为QT安装的一部分,您应该有一个用于可视化设计窗口的工具
QDesigner.exe
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.