Results 1 to 3 of 3

Thread: How to store current selection from QcomboBox in a Variable

  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Platforms
    Windows

    Default How to store current selection from QcomboBox in a Variable

    Hi,

    I'm using a UI i created using the QtDesigner with several Comboboxes in it and am wondering how to get the selected item in the combobox to store in a variable.

    by this i mean the user selects an option in one of the comboboxes, i need to take the users selection (in my case a few of the options are Chiron,Cyclops,aesir) and then store the options they selected somewhere for me to use for calculations later with data i have read from a .xls file using xlrd.

    looking around i have seen currentIndexChanged(int) to send a signal to a slot with the index of the option the user selected, however i am unsure of how to implement this to store into a variable or other container.

    Thanks in Advance
    -Angel

  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 store current selection from QcomboBox in a Variable

    QComboBox::currentIndex() and QComboBox::currentText() give you the entry number and text respectively of the currently selected item in the combo box (if there is one). The signal you named tells you when that changes. So you want something like:
    Qt Code:
    1. private:
    2. int m_diety;
    3.  
    4. ...
    5. m_deity = ui->deityCombo->currentIndex();
    6. // or
    7. m_deity = ui.deityCombo->currentIndex();
    8. // or
    9. m_deity = deityCombo->currentIndex();
    10. // depending on how you have incorporated the designer UI
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to store current selection from QcomboBox in a Variable

    as Chrish said,
    use QComboBox::currentText() to get the stored text in QComboBox.

    by this i mean the user selects an option in one of the comboboxes, i need to take the users selection (in my case a few of the options are Chiron,Cyclops,aesir) and then store the options they selected somewhere for me to use for calculations later with data i have read from a .xls file using xlrd.
    If u want to do some actions based on user selection,use activated(QString) signal
    void QComboBox::activated ( const QString & text ) [signal]
    This signal is sent when the user chooses an item in the combobox. The item's text is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged().
    hope it helps
    Bala

Similar Threads

  1. Replies: 2
    Last Post: 16th February 2011, 09:15
  2. Highlighting Current Selection
    By kavinsiva in forum Newbie
    Replies: 4
    Last Post: 1st June 2010, 14:34
  3. Highlighting Current Selection
    By kavinsiva in forum Newbie
    Replies: 2
    Last Post: 27th May 2010, 11:59
  4. Replies: 2
    Last Post: 4th April 2008, 12:00
  5. Replies: 1
    Last Post: 26th August 2007, 07:05

Tags for this Thread

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.