Your structure, class, or pointer need not be derived from any other class. You can use QVariant to hold any kind of object. First you need to use the Q_DECLARE_METATYPE macro in a header file:
Q_DECLARE_METATYPE(District *)
Q_DECLARE_METATYPE(District *)
To copy to clipboard, switch view to plain text mode
Then you can use the following to set the value in a QVariant instance:
District *d = ...
qVariantFromValue(d)
District *d = ...
qVariantFromValue(d)
To copy to clipboard, switch view to plain text mode
Then you can get the value from the QVariant instance:
QVariant item
= itemdist
->data
(1, Qt
::ToolTipRole);
District *d = item.value<District *>();
QVariant item = itemdist->data(1, Qt::ToolTipRole);
District *d = item.value<District *>();
To copy to clipboard, switch view to plain text mode
Also - look at the description of the QVariant class in the documentation - it should show you how to deal with custom structures, etc.
Bookmarks