QVariant :: QVariant(Qt :: GlobalColor)'是私有的

Ale*_*len 7 qt qt5

头文件中的声明

QColor dialogBoja, dialogBoja1;
Run Code Online (Sandbox Code Playgroud)

.cpp文件

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

正如我在标题上所说,当我尝试在Qt5中编译它时,我得到错误:QVariant :: QVariant(Qt :: GlobalColor)'是私有的

怎么解决这个问题.

Dan*_*urn 12

您需要显式创建QColor对象.这应该工作:

dialogBoja = postavke.value("boja", QColor(Qt::black)).toString();
Run Code Online (Sandbox Code Playgroud)

标题中解释了这个原因:

// 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.
Run Code Online (Sandbox Code Playgroud)