error: C2248: “QVariant::QVariant”: 无法访问 private 成员(在“QVariant”类中声明)

问题:

declaration in header file

QColor dialogBoja, dialogBoja1;

.cpp file

dialogBoja = postavke.value("boja", Qt::black).toString();
//postavke means settings
dialogBoja1 = postavke.value("boja1", Qt::white).toString();

As I said on title, when I try to compile this in Qt5 I get error: QVariant::QVariant(Qt::GlobalColor)' is private

How to solve this.

答:

You need to explicitly create a QColor object. This should work:

dialogBoja = postavke.value("boja", QColor(Qt::black)).toString();

The reason for this is explained in the header:

// 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.

原地址为:http://stackoverflow.com/questions/15008297/qvariantqvariantqtglobalcolor-is-private
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值