QMainWindow
. 正如我在互联网上使用的一些例子所建议的那样
QWidget
用于
setCentralWidget(QWidget*)
QWidget公司
程序正在崩溃。
class MyMainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MyMainWindow(QWidget *parent = 0);
~MyMainWindow();
private:
QVBoxLayout m_p1_level_vbox;
QHBoxLayout m_p2_level_vbox;
QHBoxLayout m_p2_level_hbox;
QWidget* m_central_widget;
QPushButton* m_increase_pressure;
QPushButton* m_decrease_pressure;
};
对于.cpp
MyMainWindow::MyMainWindow(QWidget *parent)
: QMainWindow(parent)
, m_central_widget(new QWidget(this))
, m_increase_pressure(new QPushButton("+", this))
, m_decrease_pressure(new QPushButton("-", this))
{
m_p2_level_hbox.addWidget(m_increase_pressure);
m_p2_level_hbox.addWidget(m_decrease_pressure);
m_p1_level_vbox.addLayout(&m_p2_level_hbox);
m_central_widget->setLayout(&m_p1_level_vbox);
setCentralWidget(m_central_widget);
}
MyMainWindow::~MyMainWindow()
{
delete m_central_widget; // commenting this line doesn't crash the program
delete m_increase_pressure;
delete m_decrease_pressure;
}
主.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyMainWindow w;
w.show();
return a.exec();
}
如果我不删除
m_central_widget
那就行了。