Hi everybody ,
I got problem regarding typecasting . I have one structure called Disrict and I want to set the object of district as data to Qtreewidgetitem.
District *dist;
itemdist->setData(1, Qt::ToolTipRole, dist);
QVariant item
= itemdist
->data
(1, Qt
::ToolTipRole);
district *temp = static_cast<district*>(temp1);
QTreeWidgetItem *itemdist = new QTreeWidgetItem();
District *dist;
itemdist->setData(1, Qt::ToolTipRole, dist);
QVariant item = itemdist->data(1, Qt::ToolTipRole);
district *temp = static_cast<district*>(temp1);
To copy to clipboard, switch view to plain text mode
But in line 5 it is showing error as
error C2440: 'static_cast' : cannot convert from 'QVariant' to 'district *'
error C2440: 'static_cast' : cannot convert from 'QVariant' to 'district *'
To copy to clipboard, switch view to plain text mode
I tried by using reinterpret_cast ,but it is showing same error . so how can I cast the variant item to district type. The main thing I want to do is assing district object to Qtreewidgetitem object and I want to get back the district object using Qtreewidgetitem object.
So please suggest me to solve this problem.
Regards,
Sudheer.
Bookmarks