从包含QUuid的QVariantList转换为QList <Quuid>

问题描述

我有一个对象,其属性声明如下:

Q_PROPERTY(QList<Quuid> topics READ topics WRITE setTopics)

我的一位同事实施了他的“应用更改”方法,如下所示:

void GetChanges(QList<QString>& names,QList<QVariant>& values)

要将更改保存到该数据结构中,我将Uid列表转换为变体列表:

QSet<QUuid> topics;

QVariantList uidList;
for (const QUuid& uid : topics)
   uidList.append(uid);

names.append("topics");
values.append(QVariant(uidList));

在他的代码中,这就是他设置属性值的方式:

item->setProperty(propName_.toLocal8Bit(),newValue_);

对于诸如QStringint等标准类型,它可以正常工作,但是在这种情况下,“ setProperty”调用现在失败了,因为QT无法转换{{ 1}}到为属性指定的类型(QVariantList)。我可以通过将属性的类型更改为QVariant<QUuid>来使其工作,但是现在这样做,没人知道该属性实际上需要什么类型,这很容易出错。

是否有针对此问题的“清洁”解决方案?我可以指定具有QList<QUuid>的{​​{1}}到QVariantList的自定义转换器吗?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...