Hi,

How can I set the data of a QTreeWidgetItem with a custom type?

I can, for example, declare my type with:

Qt Code:
  1. struct CntyData {
  2. QString Code;
  3. QString Desc;
  4. QString Desc2;
  5. QString Desc3;
  6. QString Desc4;
  7. QString Status;
  8. };
  9. typedef CntyData TCntyData;
  10. Q_DECLARE_METATYPE(TCntyData);
To copy to clipboard, switch view to plain text mode 

Then assign the custom data with:

Qt Code:
  1. TCntyData s;
  2. QVariant var;
  3. var.setValue(s);
  4.  
  5. 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:

Qt Code:
  1. TCntyData s;
  2. 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