2013-02-21 4 views
7

deklaracja w pliku nagłówkowymQVariant :: QVariant (Qt :: GlobalColor)”jest prywatny

QColor dialogBoja, dialogBoja1; 

plik .cpp

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

Jak powiedziałem na tytuł, gdy próbuję skompilować ten w Qt5 Otrzymuję komunikat o błędzie: QVariant :: QVariant (Qt :: GlobalColor) "jest prywatne

Jak rozwiązać ten problem.

Odpowiedz

9

Musisz jawnie utworzyć obiekt QColor. To powinno działać:

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

Powodem tego jest wyjaśnione w nagłówku:

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

Wygląda na to, że chcieli się rozwieść QVariant z modułów QtGui, jak QColor i usuwa tego konstruktora w 5,0. Niektóre składni wyjaśniono 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.