Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QVariant::QVariant(Qt::GlobalColor)' is private

Tags:

qt

qt5

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.

like image 712
Alen Avatar asked Feb 21 '13 17:02

Alen


2 Answers

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.
like image 74
Dan Milburn Avatar answered Oct 03 '22 17:10

Dan Milburn


Looks like they wanted to divorce QVariant from the QtGui modules, like QColor, and removed that constructor in 5.0. Some syntax is explained 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.

like image 20
Phlucious Avatar answered Sep 29 '22 17:09

Phlucious