PDA

View Full Version : updating treeview from tableview



darshan
8th February 2009, 12:58
Hello, i am currently using qt4 to program with libpcap and i have created a table view to list all the packets coming through the network interface. Each row consists of one packet and has several columns, source IP, destination IP, Date etc.

The signal for the tableview is coming from the thread and the main gui is updating the table, but i would like to create a tree view under the table to list extra information from each row in the table.

i.e by clicking on a row in table view the tree view will show items such as MAC addresses, Port numbers etc

I am really stuck on this at the moment, i have created the table view and tree view using QStandardItemModel. Do i need to store all that information somewhere and then call it when an item in a row is clicked on?

Any help would be appreciated :)

darshan
9th February 2009, 18:15
please anyone?

caduel
9th February 2009, 18:32
basically you have two possibilities:
i) connect to the currentChanged signal (of your table view) and populate the tree view with the data for the selected row in the table
ii) *if* you have (and you don't iiuyc) all the relevant data in a model M:
you can set M as the model for both views; show the relevant columns in the table view, and the details (further columns) in the tree view;
You still need to keep selections in sync: either by connecting to the selectionChanged signal (see QAbstractItemView::selectionModel()), or by simply settings the selectionModel of the treeview to that of the table view. (You would need to get rid of QStandardItemModel, I guess.)
(Ok, I cheated: this approach would give you one row in the tree. You would want to "transpose" the model... one way would be a proxy model...)

i) is simpler, so if you just want to display and not edit stuff, you can go that way.

HTH

darshan
9th February 2009, 23:48
step 1 does seem to be the right answer for me but the problem is that the function being called is continuously running in a loop.

this is what im calling from my thread class

emit addToTable(header,pkt_data);

pkt_data being the actual packet data. Now i need this parameter in order to call anything else that i need to add in the tree view. So far this function is only adding to the table view.

How would be able to add items to the tree view using pkt_data?

darshan
11th February 2009, 20:53
any ideas?