Results 1 to 3 of 3

Thread: How to get the index of row which contains a specific string?

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to get the index of row which contains a specific string?

    I have a QComboBox from which I want to extract the index of a row that contains a specific row. How can I acomplish that?
    Example:
    Qt Code:
    1. QSqlQuery qsCat("select categID,numeCateg from categ order by numeCateg");
    2. categorie->addItem("Categorie");
    3. while(qsCat.next()){
    4. categId=qsCat.value("categID").toString();
    5. numeCat=qsCat.value("numeCateg").toString();
    6. categorie->addItem(numeCat,categId);
    7. }
    To copy to clipboard, switch view to plain text mode 

    For the example let's say that
    Qt Code:
    1. categorie->addItem()
    To copy to clipboard, switch view to plain text mode 
    inserts multiple rows from which I have also
    Qt Code:
    1. categorie->addItem("Administrator","2")
    To copy to clipboard, switch view to plain text mode 

    I would like then to use categorie->setCurrentIndex(int index) where index=index where the item has "Administrator".

    Thank you

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to get the index of row which contains a specific string?


  3. The following user says thank you to ChrisW67 for this useful post:

    adutzu89 (4th February 2014)

  4. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to get the index of row which contains a specific string?

    Oh, I'm sorry, appearantly I didn't looked how I should've looked in the documentation.It happens sometimes, thank you for opening my eyes.

Similar Threads

  1. PyQT Listview index to string
    By Dariusz in forum Newbie
    Replies: 1
    Last Post: 28th September 2013, 09:05
  2. Replies: 5
    Last Post: 15th July 2013, 10:36
  3. How do I search for files which contain a specific text string?
    By rolandburt in forum General Programming
    Replies: 1
    Last Post: 20th August 2012, 21:32
  4. Replies: 2
    Last Post: 5th September 2010, 14:06
  5. Replies: 1
    Last Post: 22nd July 2010, 17:12

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.