Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. how to check the output of the QCombobox box
Forum Updated to NodeBB v4.3 + New Features

how to check the output of the QCombobox box

Scheduled Pinned Locked Moved Solved Game Development
5 Posts 4 Posters 850 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.
  • milhaoM Offline
    milhaoM Offline
    milhao
    wrote on last edited by milhao
    #1

    hi, I'm trying to compare the player's choice return in the QComboBox box to create different actions, how do I check the output of the QComboBox?

    JonBJ 1 Reply Last reply
    0
    • milhaoM milhao

      @JonB how would I use this corresponding Changed() signal.
      And another one, what is the return of QComboBox::currentIndex() or QComboBox::currentText(), because I want to get the word elf and compare it with the return of QComboBox to know if it is chosen

      ApprenticeRenoA Offline
      ApprenticeRenoA Offline
      ApprenticeReno
      wrote on last edited by
      #5

      @milhao
      I assume you drag and drop a comboBox in you're ui.file and then set the items, if this is you're case you can try :

      -Go to the ui.file , right click on the comboBox , GoToSlot -> select on CurrentTextChanged, then , in the method that is created automathically you write this:

      void MainWindow::on_comboBox_1_currentTextChanged(const QString &arg1)
      {
          if(ui->comboBox_1->currentText()=="elf"){
              qDebug()<<" you have chosen  --> "<<ui->comboBox_1->currentText();
       }else if(ui->comboBox_1->currentText()=="human"){
              qDebug()<<" you have chosen --> "<<ui->comboBox_1->currentText();
          }
      }
      
      1 Reply Last reply
      1
      • milhaoM milhao

        hi, I'm trying to compare the player's choice return in the QComboBox box to create different actions, how do I check the output of the QComboBox?

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

        @milhao
        QComboBox::currentIndex() or QComboBox::currentText().
        Corresponding ...Changed() signals if you want them.

        milhaoM 1 Reply Last reply
        3
        • JonBJ JonB

          @milhao
          QComboBox::currentIndex() or QComboBox::currentText().
          Corresponding ...Changed() signals if you want them.

          milhaoM Offline
          milhaoM Offline
          milhao
          wrote on last edited by
          #3

          @JonB how would I use this corresponding Changed() signal.
          And another one, what is the return of QComboBox::currentIndex() or QComboBox::currentText(), because I want to get the word elf and compare it with the return of QComboBox to know if it is chosen

          ApprenticeRenoA 1 Reply Last reply
          0
          • Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #4

            Check this for QComboBox properties and this for connecting signals/slots.

            Software Engineer
            The Qt Company, Oslo

            1 Reply Last reply
            0
            • milhaoM milhao

              @JonB how would I use this corresponding Changed() signal.
              And another one, what is the return of QComboBox::currentIndex() or QComboBox::currentText(), because I want to get the word elf and compare it with the return of QComboBox to know if it is chosen

              ApprenticeRenoA Offline
              ApprenticeRenoA Offline
              ApprenticeReno
              wrote on last edited by
              #5

              @milhao
              I assume you drag and drop a comboBox in you're ui.file and then set the items, if this is you're case you can try :

              -Go to the ui.file , right click on the comboBox , GoToSlot -> select on CurrentTextChanged, then , in the method that is created automathically you write this:

              void MainWindow::on_comboBox_1_currentTextChanged(const QString &arg1)
              {
                  if(ui->comboBox_1->currentText()=="elf"){
                      qDebug()<<" you have chosen  --> "<<ui->comboBox_1->currentText();
               }else if(ui->comboBox_1->currentText()=="human"){
                      qDebug()<<" you have chosen --> "<<ui->comboBox_1->currentText();
                  }
              }
              
              1 Reply Last reply
              1

              • Login

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