bauervision bauervision - 4 months ago 43
C++ Question

How to get Pointer to Index in QTreeWidget?

I have created a QTreeWidget, and populated it with struct data (, myObj.DOB, myObj.age, etc).

When I select on an item in the widget, I need to grab the pointer data associated with that selection to display it elsewhere.

I create the list with pointers, I just need to figure out how to in turn retrieve those pointers when I select on the list.


So I was able to achieve what I needed by using QMap.

QMap<QTreeWidgetItem*, myObject*> myMap_container;//declared in .h

And then in my cpp:

    void MainWindow::on_myTree_itemClicked(QTreeWidgetItem *item, int column){
       myObject* rowData = myMap_container[item];

From there I was able to access the entirety of my struct data which has been assigned like so:

cout << rowData.Name << endl;
cout << rowData.Age << endl;
cout << rowData.SSN<< endl;
cout << rowData.FavColor<< endl;