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. How can I add item in the QCombobox?
Forum Updated to NodeBB v4.3 + New Features

How can I add item in the QCombobox?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 17.4k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi All,
    I'm using qt5.5 and Linux+QT for my OS system.
    This is how I designed.

    void MainWindow::openscanwindow()
    {
        int i = 0;
        bool empty = false;
        QString scan_info;
        QString info;
        stackedWidgetTestbtselect=ui->stackedWidgetPagePanel;
        ui->stackedWidget->setCurrentWidget(stackedWidgetTestbtselect);
        btselect = new QComboBox(this);
        btselect->setEditable(true);
        Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/touch /home/bt.txt",&info);
        qDebug()<<"touch: "+info;
        Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/hciconfig hci0 piscan",&info);
        qDebug()<<"piscan: "+info;
        Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/hcitool scan > /home/bt.txt",&info);
        qDebug()<<"scan: "+info;
        QString jump;
        QFile scan("/home/bt.txt");
        if(!scan.open(QIODevice::ReadOnly|QIODevice::Text))
        {
            qDebug("cannot open bt.txt");
        }
        else
        {
            jump = scan.readLine();
            while(!empty)
            {
                scan_info=scan.readLine();
                qDebug()<<scan_info;
                if(scan_info.isEmpty())
                {
                    empty = true;
                }
                else
                {
                    scan_info = scan_info.mid(19).trimmed();
                    qDebug()<<scan_info;
                    btselect->addItem(scan_info);
                }
            }
    
        }
    
    
    }
    

    I can't show anything out in my Combobox.

    How can I solve this problem?

    Thanks in Advanced!

    Taz742T 1 Reply Last reply
    0
    • V victor wang

      Hi All,
      I'm using qt5.5 and Linux+QT for my OS system.
      This is how I designed.

      void MainWindow::openscanwindow()
      {
          int i = 0;
          bool empty = false;
          QString scan_info;
          QString info;
          stackedWidgetTestbtselect=ui->stackedWidgetPagePanel;
          ui->stackedWidget->setCurrentWidget(stackedWidgetTestbtselect);
          btselect = new QComboBox(this);
          btselect->setEditable(true);
          Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/touch /home/bt.txt",&info);
          qDebug()<<"touch: "+info;
          Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/hciconfig hci0 piscan",&info);
          qDebug()<<"piscan: "+info;
          Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/hcitool scan > /home/bt.txt",&info);
          qDebug()<<"scan: "+info;
          QString jump;
          QFile scan("/home/bt.txt");
          if(!scan.open(QIODevice::ReadOnly|QIODevice::Text))
          {
              qDebug("cannot open bt.txt");
          }
          else
          {
              jump = scan.readLine();
              while(!empty)
              {
                  scan_info=scan.readLine();
                  qDebug()<<scan_info;
                  if(scan_info.isEmpty())
                  {
                      empty = true;
                  }
                  else
                  {
                      scan_info = scan_info.mid(19).trimmed();
                      qDebug()<<scan_info;
                      btselect->addItem(scan_info);
                  }
              }
      
          }
      
      
      }
      

      I can't show anything out in my Combobox.

      How can I solve this problem?

      Thanks in Advanced!

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by
      #2

      @victor-wang said in How can I add item in the QCombobox?:

              else
              {
                  scan_info = scan_info.mid(19).trimmed();
                  qDebug()<<scan_info;
                  btselect->addItem(scan_info);
              }
      

      Does it print anything?

      Do what you want.

      V 2 Replies Last reply
      0
      • Taz742T Taz742

        @victor-wang said in How can I add item in the QCombobox?:

                else
                {
                    scan_info = scan_info.mid(19).trimmed();
                    qDebug()<<scan_info;
                    btselect->addItem(scan_info);
                }
        

        Does it print anything?

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #3

        @Taz742
        Yes it will print what I want!

        Taz742T 1 Reply Last reply
        0
        • Taz742T Taz742

          @victor-wang said in How can I add item in the QCombobox?:

                  else
                  {
                      scan_info = scan_info.mid(19).trimmed();
                      qDebug()<<scan_info;
                      btselect->addItem(scan_info);
                  }
          

          Does it print anything?

          V Offline
          V Offline
          victor wang
          wrote on last edited by
          #4

          @Taz742
          There is a strange thing happened that I can print the log out but I can't show anything in my combobox.

          1 Reply Last reply
          0
          • V victor wang

            @Taz742
            Yes it will print what I want!

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by
            #5

            @victor-wang

            void MainWindow::openscanwindow()
            {
                bselect = new QComboBox(this);
                bselect->addItem("New Item");
            }
            

            Could it be just a test to work in this case?

            Do what you want.

            Taz742T V 2 Replies Last reply
            0
            • Taz742T Taz742

              @victor-wang

              void MainWindow::openscanwindow()
              {
                  bselect = new QComboBox(this);
                  bselect->addItem("New Item");
              }
              

              Could it be just a test to work in this case?

              Taz742T Offline
              Taz742T Offline
              Taz742
              wrote on last edited by Taz742
              #6

              @Taz742 said in How can I add item in the QCombobox?:

              void MainWindow::openscanwindow()
              {
              bselect = new QComboBox(this);
              bselect->addItem("New Item");
              }

              Could it be just a test to work in this case?

              and bselect.show();

              Do what you want.

              1 Reply Last reply
              0
              • Taz742T Taz742

                @victor-wang

                void MainWindow::openscanwindow()
                {
                    bselect = new QComboBox(this);
                    bselect->addItem("New Item");
                }
                

                Could it be just a test to work in this case?

                V Offline
                V Offline
                victor wang
                wrote on last edited by
                #7

                @Taz742
                I seem to solve the problem.
                I had make a silly mistake.
                I should do like this.

                else
                        {
                            scan_info = scan_info.mid(19).trimmed();
                            qDebug()<<scan_info;
                            ui->combobox->addItem(scan_info);
                        }
                
                Taz742T 2 Replies Last reply
                0
                • V victor wang

                  @Taz742
                  I seem to solve the problem.
                  I had make a silly mistake.
                  I should do like this.

                  else
                          {
                              scan_info = scan_info.mid(19).trimmed();
                              qDebug()<<scan_info;
                              ui->combobox->addItem(scan_info);
                          }
                  
                  Taz742T Offline
                  Taz742T Offline
                  Taz742
                  wrote on last edited by Taz742
                  #8

                  @victor-wang
                  Yes.
                  The more detailed problem was the following

                      btselect = new QComboBox(this);
                  
                  

                  You may have been using it for some time but btselect = new QComboBox (this); He spoiled everything.
                  Combobox cleaned. He's the other and no longer watches the previous address.
                  If you use it only in the constructor then everything would be fine :))

                  Do what you want.

                  1 Reply Last reply
                  0
                  • V victor wang

                    @Taz742
                    I seem to solve the problem.
                    I had make a silly mistake.
                    I should do like this.

                    else
                            {
                                scan_info = scan_info.mid(19).trimmed();
                                qDebug()<<scan_info;
                                ui->combobox->addItem(scan_info);
                            }
                    
                    Taz742T Offline
                    Taz742T Offline
                    Taz742
                    wrote on last edited by
                    #9

                    @victor-wang
                    sorry for english.
                    Hopefully there will be someone who is godly and you will explain in detail.

                    Do what you want.

                    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