azf*_*azf 20
您必须使用特殊宏Q_DECLARE_METATYPE()来使QVariant系统可以使用自定义类型.
请仔细阅读文档以了解其工作原理.
对于QPair,虽然它很简单:
#include <QPair>
#include <QDebug>
typedef QPair<int,int> MyType; // typedef for your type
Q_DECLARE_METATYPE(MyType); // makes your type available to QMetaType system
int main(int argc, char *argv[])
{
// ...
MyType pair_in(1,2);
QVariant variant = QVariant::fromValue(pair_in);
MyType pair_out = variant.value<MyType>();
qDebug() << pair_out;
// ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5359 次 |
| 最近记录: |