PDA

View Full Version : Find item in table



JohnToddSr
3rd July 2009, 16:52
I need the most direct way to find an item in a table. For example, say I have a table with 3 columns and the first column contains IP addresses. Then I have a QLineEdit to enter an IP address. I now need to find which row this IP address is stored in. I know the address is in the table I just want to know which row it's in. I know and can go through a loop checking each item in the table until I get a match but surely there's a better way?

wysota
3rd July 2009, 17:24
It depends whether the items in the table are sorted. If not then you have to go though every item and compare. If you're using Qt's views, you can use QSortFilterProxyModel that will find the items for you.

If on the other hand the table is sorted, you can use faster search algorithms such as qLowerBound() or qBinaryFind().