Hi,
How can I set the data of a QTreeWidgetItem with a custom type?
I can, for example, declare my type with:
struct CntyData {
};
typedef CntyData TCntyData;
Q_DECLARE_METATYPE(TCntyData);
struct CntyData {
QString Code;
QString Desc;
QString Desc2;
QString Desc3;
QString Desc4;
QString Status;
};
typedef CntyData TCntyData;
Q_DECLARE_METATYPE(TCntyData);
To copy to clipboard, switch view to plain text mode
Then assign the custom data with:
TCntyData s;
var.setValue(s);
item->setData(0,Qt::UserRole,var);
TCntyData s;
QVariant var;
var.setValue(s);
item->setData(0,Qt::UserRole,var);
To copy to clipboard, switch view to plain text mode
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
));
TCntyData s;
item->setData(0,Qt::UserRole,QVariant(s));
To copy to clipboard, switch view to plain text mode
But it get the error: no matching function for call to 'QVariant::QVariant(TCntyData&)'
Thanks
Bookmarks