我的布局有问题。我在.cpp文件中写了这个例子:
#include <QApplication>
#include <QHBoxLayout>
#include <QSlider>
#include <QSpinBox>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window -> setWindowTitle("Enter your age please:");
QSpinBox *spinBox = new QSpinBox;
layout -> addWidget(spinBox);
window -> show();
return app.exec();
}
我用这些命令编译:
qmake -project
qmake
make
我收到此错误:
age.cpp: In function ‘int main(int, char**)’:
age.cpp:13:3: error: ‘layout’ was not declared in this scope
make: *** [age.o] Error 1
我搜索过此错误但找不到任何解决方案。有人可以帮忙吗?
答案 0 :(得分:4)
显然没有在您的源代码中声明。您应该首先声明一个QGridLayout变量,例如,如下所示:
QGridLayout * layout = new QGridLayout;
答案 1 :(得分:1)
您尚未声明布局。你需要这样的东西
// add this
QLayout *layout = new QHBoxLayout;
window->setLayout(layout);