缺少用于实现卡布局的 QLayout 构造函数

Missing QLayout constructor to implement Card Layout

本文关键字:QLayout 构造函数 布局 用于 实现      更新时间:2023-10-16

我正在尝试实现这个 CardLayout 示例 https://doc.qt.io/qt-5/layout.html 但是当我尝试编译给定的文件 card.h 时,它无法抱怨 QLayout 的构造函数,因为没有重载接受给定的参数。

我错过了这个例子吗?此示例是否仅适用于旧版本的Qt?我正在使用Qt 5.12

卡.h代码

#ifndef CARD_H
#define CARD_H
#include <QtWidgets>
#include <QList>
class CardLayout : public QLayout
{
public:
    CardLayout(QWidget *parent, int dist): QLayout(parent, 0, dist) {}
    CardLayout(QLayout *parent, int dist): QLayout(parent, dist) {}
    CardLayout(int dist): QLayout(dist) {}
private:
    QList<QLayoutItem*> list;
};
#endif

根据Qt 5.12的文档

https://doc.qt.io/qt-5/qlayout.html

QLayout 类不再有这样的构造,

你只有

QLayout(QWidget *parent)

QLayout()