//头文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QStackedLayout>
#include <QListWidget>
#include <QHBoxLayout>
#include <QObject>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_listWidget_clicked(const QModelIndex &index);
private:
Ui::Widget *ui;
QListWidget *listWidget;
QStackedLayout *sLayout;
QHBoxLayout *hLayout;
};
#endif
//源文件
#include "widget.h"
#include "ui_widget.h"
#include <QLayout>
#include <QLabel>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QListWidget *listWidget = new QListWidget();
listWidget->addItem("One");
listWidget->addItem("Two");
listWidget->addItem("Three");
QWidegt *widget1 = new QWidget();
QWidegt *widget2 = new QWidget();
QWidegt *widget3 = new QWidget();
QLabel *label1 = new QLabel("LABEL ONE", widget1);
QLabel *label2 = new QLabel("LABEL TWO", widget2);
QLabel *label3 = new QLabel("LABEL THREE", widget3);
QStackedLayout *sLayout = new QStackedLayout();
sLayout->addWidget(widget1);
sLayout->addWidget(widget2);
sLayout->addWidget(widget3);
QHBoxLayout *hLayout = QHBoxLayout();
hLayout->addWidget(listWidget);
hLayout->addLayout(sLayout);
setLayout(hLayout);
QObject::connect(listWidget, &QListWidget::currentRowChanged, sLayout, &QStackedLayout::setCurrentIndex);
}
Widget::~Widget()
{
delete ui;
}
//错误如下
编译错误: