2013-02-21 16 views
7

deklarasyonu olduğunuQVariant :: QVariant (Qt :: GlobalColor)' başlık dosyasına özel

QColor dialogBoja, dialogBoja1; 

.cpp dosyasını

Başlıkta da söylediğim gibi
dialogBoja = postavke.value("boja", Qt::black).toString(); 
//postavke means settings 
dialogBoja1 = postavke.value("boja1", Qt::white).toString(); 

, ben bu derlemeye çalıştığınızda Qt5 hata alıyorum: 'QVariant :: QVariant (Qt :: GlobalColor) bunu çözmek için nasıl

özeldir.

cevap

9

Açıkça bir QColor nesnesi oluşturmanız gerekir. Bu çalışması gerekir:

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

Bunun nedeni başlığında açıklanmıştır: onlar QColor gibi QtGui modüllerden QVariant boşanma istedi ve 5.0 bu yapıcı kaldırıldı gibi

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

görünüyor. Bazı sözdizimi here açıklanmıştır.

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.