2013-02-21 17 views
7

घोषणा हैQVariant :: QVariant (क्यूटी :: 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.

संबंधित मुद्दे