如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