#include <QVariant>
struct st
{
public:
int a;
QString str;
};
/*下面的宏让自定义类型能被QVariant识别
*/
Q_DECLARE_METATYPE(st);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
st one;
one.a = 1;
one.str = "ff";
QVariant var;
var.setValue(one);
st x = var.value<st>();
printf("%d", x.a);
return a.exec();
}