【发布时间】:2020-03-11 12:15:15
【问题描述】:
我见过How to verify QVariant of type QVariant::UserType is expected type? 并且我了解如何判断 MyType 类的对象已存储在 QVariant 对象中。我已经阅读了documentation for QVariant::convert (),但我没有按照我如何调用 MyType 中定义的成员函数来处理我作为 QVariant 收到的对象。
说我有
class MyType
{
public:
void myFunction;
.
.
.
};
Q_DELCARE_METATYPE(MyType)
MyType m;
QVariant var (QVariant::fromValue (m));
如何为保存在 var 的 MyType 对象调用 MyType::myFunction?
【问题讨论】:
-
您在寻找
QVariant::value吗?如果没有,请编辑您的问题以提供 minimal reproducible example 来展示您想要实现的目标。 -
您应该将
QVariant转换回MyType以便调用其函数。 -
@G.M.我确实在寻找 QVariant::value。谢谢你。我想我按字母顺序通读了成员函数,并在我到达那个时被斗鸡眼了。如果您将评论转换为答案,我会接受并投票。
标签: qt