【发布时间】:2018-06-27 18:50:51
【问题描述】:
我正在尝试编写一个自定义的纯 C++ QDialog,以便我可以创建一个基类并在以后继承它。以下是在 QDialog 中显示 QLabel 的代码:
“EDLController.h”
#ifndef EDLController_h
#define EDLController_h
#include <QDialog>
class EDLController : public QDialog {
Q_OBJECT
public:
EDLController(QWidget *parent = nullptr);
};
#endif
“EDLController.cpp”
EDLController::EDLController(QWidget *parent) : QDialog(parent) {
QVBoxLayout vBoxLayout;
QLabel label("text");
vBoxLayout.addWidget(&label);
setLayout(&vBoxLayout);
setWindowTitle("test");
}
“main.cpp”
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
EDLController *w = new EDLController();
w->show();
return app.exec();
}
但是,它显示了一个标题正确的空窗口: image
程序在 Raspberry Pi (Raspbian) 上运行。谁能帮我找出问题所在。
【问题讨论】:
-
vBoxLayout是EDLControllerctor 的本地对象,一旦超出范围就会被销毁。使其成为EDLController的成员。