Results 1 to 3 of 3

Thread: QComboBox currentItem

  1. #1
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QComboBox currentItem

    I have a question about QComboBox setCurrentText. I have already two default values in QComboBox Item1, Item2.

    Slot
    Qt Code:
    1. void CMainClass::readOut()
    2. {
    3.  
    4. QString str = process->readLineStdOut();
    5. comboBox->setCurrentText(str);
    6. }
    To copy to clipboard, switch view to plain text mode 

    The return value for str will be Item1 and if slot will triggerred again then str will be Item2. So return value will either Item1 or Item2 .I have problem if I use setCurrentText() method then it is overwriting my current value means ..the index 1 current value.

    How do I handle this through looping or through index such as setCurrentItem(int index) method..I want to do something like.. if str value is Item1 then I want to display that value on comboBox index 1 and if return value is Item2 then I want to display on index2.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox currentItem

    setCurrentText() changes the current item's text, not the current item. Either use QMap to map item texts to indices or go through the items until you find matching one and use setCurrentItem().

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox currentItem

    How do I handle this through looping or through index such as setCurrentItem(int index) method..I want to do something like.. if str value is Item1 then I want to display that value on comboBox index 1 and if return value is Item2 then I want to display on index2.

    Thanks.
    Try this
    Qt Code:
    1. int index = comboBox->findText(str);
    2. if(index != -1)
    3. {
    4. comboBox->setCurrentIndex(index);
    5. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  4. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 10:50
  5. QComboBox +SUSE10.0 +qt4.1 strange behavior
    By antonio.r.tome in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2006, 17:49

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.