2013-02-21 44 views
7

聲明在頭文件的QVariant ::的QVariant(QT :: GlobalColor)」是私有

QColor dialogBoja, dialogBoja1; 

.cpp文件

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

正如我標題說,當我嘗試編譯此Qt5我得到的錯誤:QVariant :: QVariant(Qt :: GlobalColor)'是私人的

如何解決這個問題。

回答

9

您需要明確創建一個QColor對象。這應該工作:

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

這樣做的原因在標題解釋:

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

看起來,他們想從QtGui模塊離婚的QVariant,喜歡的QColor,並在5.0卸下的構造。一些語法解釋爲here

Because QVariant is part of the QtCore library, it cannot provide conversion functions to data types defined in QtGui, such as QColor, QImage, and QPixmap. In other words, there is no toColor() function. Instead, you can use the QVariant::value() or the qvariant_cast() template function.

相關問題