[英]A simple qt program not running with error message saying “segmentation fault”
编译成功,但是当我运行它时,终端给了我一个“分段错误(内核已转储)”消息。 我使用的编译器是Ubuntu上的g ++。
代码是:
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>
int main(int argc, char** argv){
QApplication app(argc, argv);
QWidget window;
QLabel *label = new QLabel;
QLineEdit *edit = new QLineEdit;
QObject::connect(edit, SIGNAL(textChanged(const QString&)), label, SLOT(setText(const QString&)));
QVBoxLayout *layout;
layout->addWidget(edit);
layout->addWidget(label);
window.setLayout(layout);
window.show();
return app.exec();
}
QVBoxLayout *layout
未初始化,您使用的是未初始化的指针。
正确方法:
QVBoxLayout *layout = new QVBoxLayout;
// use layout..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.