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. refresh comboBox with new value
Forum Updated to NodeBB v4.3 + New Features

refresh comboBox with new value

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 634 Views
  • 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.
  • A Offline
    A Offline
    Alfredy
    wrote on last edited by
    #1

    Hello, i try to refresh my comboBox with another value and it don't work.!actu.png . Can you help me?

    jsulmJ 1 Reply Last reply
    0
    • A Alfredy

      Hello, i try to refresh my comboBox with another value and it don't work.!actu.png . Can you help me?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Alfredy Please post code as text!
      Is actualiser_combox() called?
      Does your code enter the if block?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alfredy
        wrote on last edited by
        #3

        void info_client::actualiser_combox(QString val)
        {
        nNumVal = val;

        if(!nNumVal.isEmpty())
        {
            ui->num->setCurrentText(nNumVal);
            qDebug()<<"VALEUR RECUPERRER "+nNumVal+" "+ui->num->currentText();
        }
        

        }

        I check if variable nNumVa is not empty before... to want to refresh.

        jsulmJ 1 Reply Last reply
        0
        • A Alfredy

          void info_client::actualiser_combox(QString val)
          {
          nNumVal = val;

          if(!nNumVal.isEmpty())
          {
              ui->num->setCurrentText(nNumVal);
              qDebug()<<"VALEUR RECUPERRER "+nNumVal+" "+ui->num->currentText();
          }
          

          }

          I check if variable nNumVa is not empty before... to want to refresh.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Alfredy I know what you want. Please answer my two questions...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • A Offline
            A Offline
            Alfredy
            wrote on last edited by
            #5

            Ok, sorry, indeed I get a value from an old interface so I want to display this value in my comboBox , the function I wrote allowing to update my comboBox with the value received is the one whose code is currently sent. But it happens that the value is not showing in the comBobox although I retrieve it correctly in my console with the qDebug below that you see... Thanks

            jsulmJ 1 Reply Last reply
            0
            • A Alfredy

              Ok, sorry, indeed I get a value from an old interface so I want to display this value in my comboBox , the function I wrote allowing to update my comboBox with the value received is the one whose code is currently sent. But it happens that the value is not showing in the comBobox although I retrieve it correctly in my console with the qDebug below that you see... Thanks

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Alfredy Is your combo box set as editable?
              Please read https://doc.qt.io/qt-6/qcombobox.html#currentText-prop
              "If the combo box is editable, the current text is the value displayed by the line edit. Otherwise, it is the value of the current item or an empty string if the combo box is empty or no current item is set."

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Alfredy
                wrote on last edited by
                #7

                Thanks @jsulm for you help, Yes my comboBox was editable but I change this, and I try to use setEditable for modify my comboBox value but it is same problem.

                jsulmJ 1 Reply Last reply
                0
                • A Alfredy

                  Thanks @jsulm for you help, Yes my comboBox was editable but I change this, and I try to use setEditable for modify my comboBox value but it is same problem.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Alfredy Sorry, I don't understand: what did you change? You made your combo box not-editable? In that case setCurrentText will try to find a text in the combo box like the one you're trying to set and then sets the current index if found. If not found nothing will happen. It is explained in the documentation, please read it:
                  "The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index."

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Alfredy
                    wrote on last edited by
                    #9

                    You made your combo box not-editable?

                    Yes

                    Thanks.

                    JonBJ 1 Reply Last reply
                    0
                    • A Alfredy

                      You made your combo box not-editable?

                      Yes

                      Thanks.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @Alfredy
                      If you made the combo not-editable it will not work.

                      Why don't you replace your whole body code (get rid of the if) with:

                      qDebug() << "Setting value";
                      ui->num->setCurrentText("1234");
                      qDebug()<<"Set value " + ui->num->currentText();
                      

                      and see what happens?

                      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