Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox::currentText()
Forum Updated to NodeBB v4.3 + New Features

QComboBox::currentText()

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 6.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tecky
    wrote on last edited by
    #1

    my problem still non solved:
    i start a program and change item manually (from 1 to 2), so in my opinion currentText() is "2" now, but QLabel always show me "abc1", why? i change it!
    @
    {
    QApplication a(argc, argv);
    QWidget w;
    QComboBox* cmb = new QComboBox;
    QLabel* lbl = new QLabel();
    cmb->addItem("1");
    cmb->addItem("2");
    lbl->setText("abc"+cmb->currentText());
    cmb->show();
    lbl->show();

    return a.exec();
    

    }
    @

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      "QLabel" is not aware that you changed selection.

      use QComboBox::currentIndexChanged signal to update your QLabel.


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mario84
        wrote on last edited by
        #3

        how should the label know that it has to display another text?

        you have to connect QComboBox::currentTextChanged to QLabel::setText (or your own slot, if you want to modify the text before displaying it)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          You have a fundamental problem with the setup of your application. You are showing "main.cpp". This part will be executed and the program will "wait" in a.exec() when you are able to change the items in the combobox. As mentioned by the others above you require the signal & slot logic for proper working. You should study some of the examples eg. "this one":http://qt-project.org/doc/qt-5.0/qtwidgets/dialogs-standarddialogs.html

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tecky
            wrote on last edited by
            #5

            ok. how about that?
            @
            QObject::connect(cmb, SIGNAL(currentTextChanged(QString)),
            cmb, SLOT (setCurrentText(QString))
            ); // now combobox know about changed item yes? or its just stupid lines?

            if (cmb->currentText() == "Item2") {
                  //do something
                    }
            

            @

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rahul Das
              wrote on last edited by
              #6

              And what do you get after execution ? :)


              Declaration of (Platform) independence.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tecky
                wrote on last edited by
                #7

                i dont know :)
                i just need to change my cmb->currentText() after changing it manually (item 1 to item 2)
                help me)

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rahul Das
                  wrote on last edited by
                  #8

                  @ QObject::connect(cmb, SIGNAL(currentIndexChanged(QString)),
                  lbl, SLOT (setText(QString)));@

                  Try with this...


                  Declaration of (Platform) independence.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tecky
                    wrote on last edited by
                    #9

                    y i did it after 1-2 reply. it works but cmb->currentText() is stll have 1st item...
                    now i try to understand 3rd reply

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Mario84
                      wrote on last edited by
                      #10

                      calling currentText() after the connect will of course give you the text of the first item, because it is executed before you change the selection in the GUI.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved