gpt4 book ai didi

qt - QVariant::QVariant(Qt::GlobalColor)' 是私有(private)的

转载 作者:行者123 更新时间:2023-12-04 10:08:43 25 4
gpt4 key购买 nike

头文件中的声明

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)' is private

如何解决这个问题。

最佳答案

您需要显式创建一个 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.

关于qt - QVariant::QVariant(Qt::GlobalColor)' 是私有(private)的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15008297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com