Results 1 to 5 of 5

Thread: how to select QComboBox option which matches a QString contents

  1. #1
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default how to select QComboBox option which matches a QString contents

    hi,
    I have a problem in setting the desired option from the QComboBox.I have QComboBox with 9 drop down options.I am reading a string(which matches one of the options in drop down list) from a .csv file.Now i want the option present in the String to be displayed in the QComboBox.Please help me in achieving this ASAP.I went through docs but i am not getting it.

    Thanks..

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to select QComboBox option which matches a QString contents

    Ok from what I understand is that you want to load the contents from .csv to QComboBox.
    1. Use QString::split function to get a QStringList of strings in .csv . More complicated options if required can be provided by QRegExp.
    2. Load the QStringList to QComboBox::addItems()

  3. #3
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: how to select QComboBox option which matches a QString contents

    u r partially correct.But the thing is i have a QComboBox with 9 options e.g Cadres like HR,SE.....i have stored particular cadre for particular user in file along with other details so when i want to see or edit his/her details then i need to display that file cadre into QComboxBox i.e it should show the cadre selected from file as currentItem/at currentIndex in QComboBox along with other 8 options.So that i can edit or retain same cadre from the QComboBox.
    For that i am using a QString for storing cadre from file.Now i want to set that cadre to QComboBox.I think u got my problem now.

  4. #4
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to select QComboBox option which matches a QString contents

    If you already have QComboBox populated and want to set index based on string matching use:
    1. QComboBox::findText() to find index of string.
    2. QComboBox::setCurrentIndex to set appropriated index.

  5. #5
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: how to select QComboBox option which matches a QString contents

    Thank you pkj.. i got it solved...

Similar Threads

  1. QCombobox contents not adjusting itself properly
    By anju123 in forum Qt Programming
    Replies: 4
    Last Post: 6th April 2016, 21:11
  2. How to select the contents of <a ..> .. </a> in a QTextBrowser
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 25th May 2011, 12:31
  3. signals and slot...can i select my option ?
    By salmanmanekia in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2008, 11:44
  4. Contents not Properly Visible in QComboBox
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 25th September 2007, 12:32
  5. Cannot select an item in QComboBox
    By Declan in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2007, 08:08

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.