Results 1 to 6 of 6

Thread: how do I use comboBox

  1. #1
    Join Date
    Aug 2012
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default how do I use comboBox

    I want to use a comboBox but am having some problems with the signals. I want to have comboBox with the options

    cat
    dog
    mouse

    then when I click a pushButton (which I have already tested and coded) it calls the appropriate function. So the pushButton has the option of calling 3 different functions depending if the user has selected cat, dog or mouse from the comboBox. I know the code below isn't right but hopefully explains the idea.

    Qt Code:
    1. if (comboBox == cat){
    2. cat();
    3. }
    4.  
    5. if (comboBox == dog){
    6. dog();
    7. }
    To copy to clipboard, switch view to plain text mode 

  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: how do I use comboBox

    And what is the question?
    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.


  3. #3
    Join Date
    Aug 2012
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how do I use comboBox

    What is the code to achieve what I have explained above.

  4. #4
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: how do I use comboBox

    And I dind't understand the use of QPushButton in your requirement.
    But you can invoke this signal - void currentIndexChanged(const QString & text)

    I think this helps
    Qt Code:
    1. connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onComboIndexChanged(QString)));
    2.  
    3. // Write your slot something like this
    4. void CYourClass::onComboIndexChanged(QString str)
    5. {
    6. if(str == "cat")
    7. {
    8. cat();
    9. }
    10. else if(str == "dog")
    11. {
    12. dog();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 2nd July 2013 at 12:12.

  5. #5
    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: how do I use comboBox

    Quote Originally Posted by QT++ View Post
    What is the code to achieve what I have explained above.
    Connect to the button's clicked() signal and check the current index of the combobox.
    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.


  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how do I use comboBox

    Qt Code:
    1. if (comboBox->currentText() == "cat")
    To copy to clipboard, switch view to plain text mode 
    or, if you know that "cat" is the first option, as wysota said

    Qt Code:
    1. if (comboBox->currentIndex() == 0)
    To copy to clipboard, switch view to plain text mode 

    cheers,
    _

Similar Threads

  1. Depending Combobox
    By cia.michele in forum Qt Programming
    Replies: 1
    Last Post: 10th January 2012, 17:11
  2. Help ComboBox
    By vinny gracindo in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 19:41
  3. ComboBox into String
    By Nefastious in forum Newbie
    Replies: 6
    Last Post: 15th October 2009, 11:50
  4. ComboBox of bmp:s
    By SailinShoes in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2008, 15:22
  5. QTableWidget combobox
    By aekilic in forum Qt Programming
    Replies: 14
    Last Post: 17th September 2007, 14:39

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.