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 to read the Selected combo box text in Qt XML
Forum Updated to NodeBB v4.3 + New Features

how to read the Selected combo box text in Qt XML

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 1.9k 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.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by
    #1

    i have two label and two combo box that is in the tab widget ,

    (label)-COUNTRY --INDIA(combobox)
    ------------------- AMERICA(combobox)
    (label)-LANGUAGE - ENGLISH(combobox)
    -------------------- FRENCH(combobox)

    these are my label and combobox text
    if i selectd the country and language and then press ok button ,the xml sheet be like this ,

    xml sheet,

    <country = "india"/>
    <language="English"/>

    i dont know how to do this,I Tried a lot please try to resolve my problem guys

    Thanks in Advance guys .

    RatzzR 1 Reply Last reply
    0
    • T Offline
      T Offline
      TioRoy
      wrote on last edited by
      #2

      Did you read the docs?

      http://doc.qt.io/qt-5/qxmlstreamwriter.html#details

      sankarapandiyanS 1 Reply Last reply
      4
      • T Offline
        T Offline
        TioRoy
        wrote on last edited by
        #3

        For combo Value:
        https://stackoverflow.com/questions/2056915/how-can-i-get-the-selected-value-out-of-a-qcombobox

        combobox->itemData(combobox->currentIndex())
        
        sankarapandiyanS 1 Reply Last reply
        2
        • sankarapandiyanS sankarapandiyan

          i have two label and two combo box that is in the tab widget ,

          (label)-COUNTRY --INDIA(combobox)
          ------------------- AMERICA(combobox)
          (label)-LANGUAGE - ENGLISH(combobox)
          -------------------- FRENCH(combobox)

          these are my label and combobox text
          if i selectd the country and language and then press ok button ,the xml sheet be like this ,

          xml sheet,

          <country = "india"/>
          <language="English"/>

          i dont know how to do this,I Tried a lot please try to resolve my problem guys

          Thanks in Advance guys .

          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by
          #4

          @sankarapandiyan

          using QXmlStreamWriter class.

          #include <QXmlStreamWriter>
          
          void MainWindow::on_pushButton_OK_clicked()
          {
              QFile file("C:\\Users\\Name\\Desktop\\test2.xml");
              if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                  return;
          
              QXmlStreamWriter stream(&file);
              stream.setAutoFormatting(true);
              stream.writeStartDocument();
              stream.writeStartElement("country");
              stream.writeAttribute("",ui->comboBox_COUNTRY->currentText());
              stream.writeEndElement();
          
              stream.writeStartElement("language");
              stream.writeAttribute("",ui->comboBox_LANGUAGE->currentText());
              stream.writeEndElement(); 
          
              file.close();
          }

          --Alles ist gut.

          sankarapandiyanS 1 Reply Last reply
          2
          • RatzzR Ratzz

            @sankarapandiyan

            using QXmlStreamWriter class.

            #include <QXmlStreamWriter>
            
            void MainWindow::on_pushButton_OK_clicked()
            {
                QFile file("C:\\Users\\Name\\Desktop\\test2.xml");
                if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                    return;
            
                QXmlStreamWriter stream(&file);
                stream.setAutoFormatting(true);
                stream.writeStartDocument();
                stream.writeStartElement("country");
                stream.writeAttribute("",ui->comboBox_COUNTRY->currentText());
                stream.writeEndElement();
            
                stream.writeStartElement("language");
                stream.writeAttribute("",ui->comboBox_LANGUAGE->currentText());
                stream.writeEndElement(); 
            
                file.close();
            }
            sankarapandiyanS Offline
            sankarapandiyanS Offline
            sankarapandiyan
            wrote on last edited by sankarapandiyan
            #5

            @Ratzz if the label and combo box is more than 10
            i am not able to write stream.writeStartElement("country"); for each one ,so instaed of this how to do the following pls resolve it this is my main doubt and how to write in loop for the following

            RatzzR 1 Reply Last reply
            0
            • T TioRoy

              For combo Value:
              https://stackoverflow.com/questions/2056915/how-can-i-get-the-selected-value-out-of-a-qcombobox

              combobox->itemData(combobox->currentIndex())
              
              sankarapandiyanS Offline
              sankarapandiyanS Offline
              sankarapandiyan
              wrote on last edited by
              #6

              @TioRoy sure but i dont know how to diaplay the label in loop that is the big doubt for me kindly resolve it pls thanks in advanz

              1 Reply Last reply
              0
              • T TioRoy

                Did you read the docs?

                http://doc.qt.io/qt-5/qxmlstreamwriter.html#details

                sankarapandiyanS Offline
                sankarapandiyanS Offline
                sankarapandiyan
                wrote on last edited by
                #7

                @TioRoy yes done

                1 Reply Last reply
                0
                • sankarapandiyanS sankarapandiyan

                  @Ratzz if the label and combo box is more than 10
                  i am not able to write stream.writeStartElement("country"); for each one ,so instaed of this how to do the following pls resolve it this is my main doubt and how to write in loop for the following

                  RatzzR Offline
                  RatzzR Offline
                  Ratzz
                  wrote on last edited by
                  #8

                  @sankarapandiyan said in how to read the Selected combo box text in Qt XML:

                  if the label and combo box is more than 10

                  What is the parent widget on which u have all label and combobox?

                  --Alles ist gut.

                  sankarapandiyanS 1 Reply Last reply
                  1
                  • RatzzR Ratzz

                    @sankarapandiyan said in how to read the Selected combo box text in Qt XML:

                    if the label and combo box is more than 10

                    What is the parent widget on which u have all label and combobox?

                    sankarapandiyanS Offline
                    sankarapandiyanS Offline
                    sankarapandiyan
                    wrote on last edited by
                    #9

                    @Ratzz
                    Labels and combo boxes are all in tab widget
                    this is my code,

                    MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    }

                    MainWindow::~MainWindow()
                    {
                    delete ui;
                    }

                    void MainWindow::on_pushButton_clicked()
                    {
                    {
                    QFile file("/home/newuser/Desktop/testt.xml");
                    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                    return;

                        QXmlStreamWriter stream(&file);
                        stream.setAutoFormatting(true);
                        stream.writeStartDocument();
                        stream.writeStartElement("country");
                        stream.writeAttribute("",ui->comboBox_COUNTRY->currentText());
                        stream.writeEndElement();
                    
                        stream.writeStartElement("language");
                        stream.writeAttribute("",ui->comboBox_LANGUAGE->currentText());
                        stream.writeEndElement();
                    
                        file.close();
                    }
                    

                    }

                    RatzzR 1 Reply Last reply
                    0
                    • sankarapandiyanS sankarapandiyan

                      @Ratzz
                      Labels and combo boxes are all in tab widget
                      this is my code,

                      MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                      {
                      ui->setupUi(this);
                      }

                      MainWindow::~MainWindow()
                      {
                      delete ui;
                      }

                      void MainWindow::on_pushButton_clicked()
                      {
                      {
                      QFile file("/home/newuser/Desktop/testt.xml");
                      if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                      return;

                          QXmlStreamWriter stream(&file);
                          stream.setAutoFormatting(true);
                          stream.writeStartDocument();
                          stream.writeStartElement("country");
                          stream.writeAttribute("",ui->comboBox_COUNTRY->currentText());
                          stream.writeEndElement();
                      
                          stream.writeStartElement("language");
                          stream.writeAttribute("",ui->comboBox_LANGUAGE->currentText());
                          stream.writeEndElement();
                      
                          file.close();
                      }
                      

                      }

                      RatzzR Offline
                      RatzzR Offline
                      Ratzz
                      wrote on last edited by Ratzz
                      #10

                      @sankarapandiyan said in how to read the Selected combo box text in Qt XML:

                      Labels and combo boxes are all in tab widget

                      There are other label and comboboxes apart from the one you want to be write on that tabwidget?

                      Can you show your tab widget?

                      --Alles ist gut.

                      1 Reply Last reply
                      1
                      • sankarapandiyanS Offline
                        sankarapandiyanS Offline
                        sankarapandiyan
                        wrote on last edited by
                        #11

                        yes all are in the tab widget @Ratzz

                        RatzzR 1 Reply Last reply
                        0
                        • sankarapandiyanS sankarapandiyan

                          yes all are in the tab widget @Ratzz

                          RatzzR Offline
                          RatzzR Offline
                          Ratzz
                          wrote on last edited by
                          #12

                          @sankarapandiyan

                          I have tested for 2 combination of label and combobox.

                              QXmlStreamWriter stream(&file);
                              stream.setAutoFormatting(true);
                              stream.writeStartDocument();
                          
                              QWidget* pWidget=  ui->mwtabwidget->widget(yourTabIndex);
                              QList<QLabel *> labelList = pWidget->findChildren<QLabel *>();
                              QStringList comboList ={ ui->comboBox_COUNTRY->currentText(), 
                                                       ui->comboBox_LANGUAGE->currentText()} ;
                          
                              for (int cc = 0; cc < labelList.count(); ++cc)
                              {
                                  stream.writeStartElement(labelList.at(cc)->text());
                                  stream.writeAttribute("",comboList.at(cc));
                                  stream.writeEndElement();
                              }
                              file.close();
                          

                          Your combox index should be in same order of label. Someone else may have better solution.

                          --Alles ist gut.

                          sankarapandiyanS 1 Reply Last reply
                          3
                          • RatzzR Ratzz

                            @sankarapandiyan

                            I have tested for 2 combination of label and combobox.

                                QXmlStreamWriter stream(&file);
                                stream.setAutoFormatting(true);
                                stream.writeStartDocument();
                            
                                QWidget* pWidget=  ui->mwtabwidget->widget(yourTabIndex);
                                QList<QLabel *> labelList = pWidget->findChildren<QLabel *>();
                                QStringList comboList ={ ui->comboBox_COUNTRY->currentText(), 
                                                         ui->comboBox_LANGUAGE->currentText()} ;
                            
                                for (int cc = 0; cc < labelList.count(); ++cc)
                                {
                                    stream.writeStartElement(labelList.at(cc)->text());
                                    stream.writeAttribute("",comboList.at(cc));
                                    stream.writeEndElement();
                                }
                                file.close();
                            

                            Your combox index should be in same order of label. Someone else may have better solution.

                            sankarapandiyanS Offline
                            sankarapandiyanS Offline
                            sankarapandiyan
                            wrote on last edited by
                            #13

                            @Ratzz thanks a Lot

                            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