Results 1 to 9 of 9

Thread: QComboBox

  1. #1
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QComboBox

    How can I get the selected VALUE out of a QCombobox & Count the Values form QComboBox?

    I have to get values from QComboBox...and count how many columns are inserted in QComboBox

    Kindly Do Needful....

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QComboBox

    Have you looked at the documentation for QComboBox? Specifically QComboBox::count and QComboBox::currentText might be useful to you.

  3. #3
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QComboBox

    Thanks for u r advice...


    i tried currentText...it is getting only first item value....when i press second item didn't print second value...


    Here is the Code....

    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3. #include <QPushButton>
    4. #include <QWidget>
    5. #include <QComboBox>
    6. #include <QDialog>
    7. #include <QVBoxLayout>
    8. #include <QMessageBox>
    9. #include <stdio.h>
    10. #include <QDebug>
    11.  
    12. int main(int argc,char* argv[])
    13. {
    14.  
    15. QApplication a(argc, argv);
    16. char str[34]= "12333";
    17. char str1[10]= "267788";
    18. char str2[12]= "39987";
    19.  
    20.  
    21. QVBoxLayout *layout = new QVBoxLayout(&w);
    22. QLabel *label = new QLabel("Plz Select the items in ComboBox");
    23. QComboBox *combo = new QComboBox();
    24. layout->addWidget(label);
    25. layout->addWidget(combo);
    26. combo->addItem(str);
    27. combo->addItem(str1);
    28. combo->addItem(str2);
    29. QString val = combo->currentText();
    30. qDebug()<<val;
    31.  
    32. QObject::connect(combo, SIGNAL(currentIndexChanged(QString)), label, SLOT(setText(QString)));
    33.  
    34. w.show();
    35.  
    36. return a.exec();
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 
    ....PFA
    Last edited by anda_skoa; 1st April 2015 at 10:06. Reason: missing [code] tags

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QComboBox

    Unless I am mistaken, QComboBox only supports a single selection. Perhaps others may know of a way to accomplish this, but I see nothing in QComboBox documentation that leads me to believe it supports multiple selections.

  5. #5
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QComboBox

    But TopLayout if u press multiple selections it is updating...

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QComboBox

    Quote Originally Posted by mandlakoteswar2011 View Post
    But TopLayout if u press multiple selections updated...
    Sorry, I have no idea what you just said...

  7. #7
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QComboBox

    iam adding QVBoxLayout what ever text in QcomBox...it is perfectly updated...but when iam printing text in QComboBox...only single Item only printed...

  8. #8
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QComboBox

    The code you are using above and what you originally asked was how to get the text for the currently selected item. If you want to print all entries in the QComboBox, you'll have to loop through all of the entries like:

    Qt Code:
    1. for (int i = 0; i < combo->count(); i++)
    2. {
    3. QString text = combo->itemText(i);
    4. qDebug() << text;
    5. }
    To copy to clipboard, switch view to plain text mode 
    Is that what you are looking for?

  9. #9
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QComboBox

    Thanks guru really....its working ....I modified according the my Requiremet...

Similar Threads

  1. QComboBox
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2014, 14:14
  2. Qcombobox
    By Project25 in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2009, 19:29
  3. QComboBox
    By kavinsiva in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2009, 16:11
  4. QComboBox
    By bismitapadhy in forum Qt Programming
    Replies: 7
    Last Post: 15th July 2009, 06:01
  5. QComboBox
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2007, 06:38

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.