Results 1 to 2 of 2

Thread: Find item in table

  1. #1
    Join Date
    Dec 2006
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Find item in table

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Find item in table

    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().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt4 Table Item Spanning
    By billyp in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2008, 17:11
  2. find item in QListView
    By AD in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 13:50
  3. Replies: 2
    Last Post: 13th September 2008, 13:55
  4. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  5. Replies: 17
    Last Post: 31st March 2006, 05:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.