我最近开始使用Qt和Qwt。我自己找不到错误,请帮助我。这是代码。 我知道我的错误在这里的某个地方:
.h文件
...
class MainWindow : public
QMainWindow
{
Q_OBJECT
QWidget *centralWidget;
public:
MainWindow(QWidget *parent = 0);
...
}
.cpp
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent) {
...
...
void MainWindow::setPlotButton() {
button = new QPushButton("push"),
button->setCheckable(true);
connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)))
QHBoxLayout *plotsLayout = new QHBoxLayout;
plotsLayout->setSpacing(10);
plotsLayout->addWidget(funPlot);
QHBoxLayout *buttonsLayout = new QHBoxLayout ;
buttonsLayout->addWidget(button);
QVBoxLayout *widgetLayout = new QVBoxLayout;
widgetLayout->addLayout(plotsLayout);
widgetLayout->addLayout(buttonsLayout);
setLayout(widgetLayout);
...
}
我收到了一条消息:"QWidget::setLayout: Attempting to set QLayout "" on MainWindow "", which already has a layout"。我发现我需要使用一个函数setCentralWidget(),但我应该改变什么呢?