qlands
4th July 2011, 14:52
Hi,
How can I set the data of a QTreeWidgetItem with a custom type?
I can, for example, declare my type with:
struct CntyData {
QString Code;
QString Desc;
QString Desc2;
QString Desc3;
QString Desc4;
QString Status;
};
typedef CntyData TCntyData;
Q_DECLARE_METATYPE(TCntyData);
Then assign the custom data with:
TCntyData s;
QVariant var;
var.setValue(s);
item->setData(0,Qt::UserRole,var);
But how can I do this without creating QVariant var and just passing s to setData.
I tried:
TCntyData s;
item->setData(0,Qt::UserRole,QVariant(s));
But it get the error: no matching function for call to 'QVariant::QVariant(TCntyData&)'
Thanks
How can I set the data of a QTreeWidgetItem with a custom type?
I can, for example, declare my type with:
struct CntyData {
QString Code;
QString Desc;
QString Desc2;
QString Desc3;
QString Desc4;
QString Status;
};
typedef CntyData TCntyData;
Q_DECLARE_METATYPE(TCntyData);
Then assign the custom data with:
TCntyData s;
QVariant var;
var.setValue(s);
item->setData(0,Qt::UserRole,var);
But how can I do this without creating QVariant var and just passing s to setData.
I tried:
TCntyData s;
item->setData(0,Qt::UserRole,QVariant(s));
But it get the error: no matching function for call to 'QVariant::QVariant(TCntyData&)'
Thanks