I have a MainWindow class that inherits from QMainWindow. I have another LayoutWindow class that inherits from QLayout. When I declare an instance of the LayoutWindow class, I have an error:
error: invalid new-expression of abstract class type ...
I do not understand because QMainWindow inherits from QWidget which inherits from QLayout?
Here is my code :
Class MainWindow :
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{//instance class LayoutWindow
layoutwindow=new LayoutWindow();
centralArea = new QWidget;
centralArea->setLayout(layoutwindow);
setCentralWidget(centralArea);
}
Class LayoutWindow.h
class LayoutWindow : public QLayout{
Q_OBJECT
public:
LayoutWindow();
};
class 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.
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
has a layout member , which arranges child widgets.
I also don't think that you need a class that derives from 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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.