【QT】PenStyle error C2248: ”QVariant::QVariant”: 无法访问 private 成员

QVariant(Qt::SolidLine)报错:

1> error C2248: “QVariant::QVariant”: 无法访问 private 成员(在“QVariant”类中声明)
1>     c:\qt\qt5.9.7\5.9.7\msvc2013_64\include\qtcore\qvariant.h(487) : 参见“QVariant::QVariant”的声明
1>     c:\qt\qt5.9.7\5.9.7\msvc2013_64\include\qtcore\qvariant.h(129) : 参见“QVariant”的声明

QVariant构造函数不支持Qt::PenStyle等枚举,见include\QtCore\qvariant.h

private:
    // force compile error, prevent QVariant(bool) to be called
    inline QVariant(void *) Q_DECL_EQ_DELETE;
    // QVariant::Type is marked as \obsolete, but we don't want to
    // provide a constructor from its intended replacement,
    // QMetaType::Type, instead, because the idea behind these
    // constructors is flawed in the first place. But we also don't
    // want QVariant(QMetaType::String) to compile and falsely be an
    // int variant, so delete this constructor:
    QVariant(QMetaType::Type) Q_DECL_EQ_DELETE;

    // These constructors don't create QVariants of the type associcated
    // with the enum, as expected, but they would create a QVariant of
    // type int with the value of the enum value.
    // Use QVariant v = QColor(Qt::red) instead of QVariant v = Qt::red for
    // example.
    QVariant(Qt::GlobalColor) Q_DECL_EQ_DELETE;
    QVariant(Qt::BrushStyle) Q_DECL_EQ_DELETE;
    QVariant(Qt::PenStyle) Q_DECL_EQ_DELETE;
    QVariant(Qt::CursorShape) Q_DECL_EQ_DELETE;

解决办法:强转为int,如QVariant(static_cast<int>(Qt::SolidLine))

How to declare Qt::PenStyle in Qt5?
Qt的QVariant类中被禁止的枚举GlobalColor、BrushStyle、PenStyle和CursorShape

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值