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 text of pushbutton in XML Qt
Forum Updated to NodeBB v4.3 + New Features

how to read the text of pushbutton in XML Qt

Scheduled Pinned Locked Moved Solved General and Desktop
46 Posts 5 Posters 8.7k 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 sankarapandiyan

    @Ratzz i think it will work i will try thanks a lot

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

    @sankarapandiyan

    May be this

    void MainWindow::on_okbutn_clicked()
    {
        QDomDocument document;
    
        QDomElement root = document.createElement("pushbuttn_text");
        document.appendChild(root);
    
        QDomElement elemTab1  = document.createElement("ss");
        root.appendChild(elemTab1 );
    
        QString text1 = ui->pushbutton1->text();
        QDomText t = document.createTextNode(text1);
        elemTab1 .appendChild(t);
    
        QFile file("C:\\Users\\name\\Desktop\\test.xml");
        if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            qDebug() << "Open the file for writing failed";
        } else {
            QTextStream stream(&file);
            stream << document.toString();
            file.close();
            qDebug() << "Writing is done";
        }
    }

    --Alles ist gut.

    sankarapandiyanS 1 Reply Last reply
    1
    • RatzzR Ratzz

      @sankarapandiyan

      May be this

      void MainWindow::on_okbutn_clicked()
      {
          QDomDocument document;
      
          QDomElement root = document.createElement("pushbuttn_text");
          document.appendChild(root);
      
          QDomElement elemTab1  = document.createElement("ss");
          root.appendChild(elemTab1 );
      
          QString text1 = ui->pushbutton1->text();
          QDomText t = document.createTextNode(text1);
          elemTab1 .appendChild(t);
      
          QFile file("C:\\Users\\name\\Desktop\\test.xml");
          if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
              qDebug() << "Open the file for writing failed";
          } else {
              QTextStream stream(&file);
              stream << document.toString();
              file.close();
              qDebug() << "Writing is done";
          }
      }
      sankarapandiyanS Offline
      sankarapandiyanS Offline
      sankarapandiyan
      wrote on last edited by sankarapandiyan
      #23

      @Ratzz yes it works but its repeat for three times i dont know why ! :-(
      but anyway thanks all for helping me

      RatzzR 1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #24

        For people passing by, using the entire xml module for operations like these is like using a bazooka to kill a fly.
        QXmlStreamWriter is more than enough and it's also probably easier to use

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

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

          @VRonin yeah! i know i will try surely

          1 Reply Last reply
          0
          • sankarapandiyanS sankarapandiyan

            @Ratzz yes it works but its repeat for three times i dont know why ! :-(
            but anyway thanks all for helping me

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

            @sankarapandiyan said in how to read the text of pushbutton in XML Qt:

            but its repeat for three times i dont know why ! :-(

            Can I see your code??

            --Alles ist gut.

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

              @Ratzz <pushbuttn_text>
              <Scanmode tab1="DEFAULT"/>
              <ss 3D_WIDE="">3D_WIDE</ss>
              </pushbuttn_text>
              <pushbuttn_text>
              <Scanmode tab2="MACULA"/>
              <ss 3D_WIDE="">3D_WIDE</ss>
              </pushbuttn_text>
              <pushbuttn_text>
              <Scanmode tab3="GLAUCOMA"/>
              <ss 3D_WIDE="">3D_WIDE</ss>
              </pushbuttn_text>

              RatzzR 1 Reply Last reply
              0
              • sankarapandiyanS sankarapandiyan

                @Ratzz <pushbuttn_text>
                <Scanmode tab1="DEFAULT"/>
                <ss 3D_WIDE="">3D_WIDE</ss>
                </pushbuttn_text>
                <pushbuttn_text>
                <Scanmode tab2="MACULA"/>
                <ss 3D_WIDE="">3D_WIDE</ss>
                </pushbuttn_text>
                <pushbuttn_text>
                <Scanmode tab3="GLAUCOMA"/>
                <ss 3D_WIDE="">3D_WIDE</ss>
                </pushbuttn_text>

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

                @sankarapandiyan
                Its the output.
                You may have pressed button 3 times?
                Can you show me CODE?

                --Alles ist gut.

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

                  @Ratzz

                         {                          
                              QDomDocument document;
                               QDomElement root = document.createElement("OCT_TOUCH");
                                document.appendChild(root);
                                qDebug() <<ui->wide3ddefltbtn->text ();
                  
                                     for (int var = 0; var < ui->mwtabwidget->count(); ++var) {
                                     qDebug() << ui->mwtabwidget->tabText(var);
                  
                                   QString text = ui->mwtabwidget->tabText(var);
                                   QDomElement elemTab = document.createElement("Scanmode") ;
                                    elemTab.setAttribute("tab"+QString::number(var+1), text);
                          
                          
                          QDomElement root = document.createElement("pushbuttn_text");
                              document.appendChild(root);
                              QDomElement elemTab1  = document.createElement("ss");
                              root.appendChild(elemTab1 );
                  
                              QString text1 = ui->wide3ddefltbtn->text();
                              QDomText t = document.createTextNode(text1);
                              elemTab1 .appendChild(t);
                              root.appendChild(elemTab);
                   }
                  
                        QString filename1 = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/home/newuser/Desktop/filenamemw.xml";
                        QFile file("/home/newuser/Desktop/filenamemw.xml");
                        if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
                          qDebug() << "Open the file for writing failed";
                        } else {
                          QTextStream stream(&file);
                          stream << document.toString();
                          file.close();
                          qDebug() << "Writing is done";
                        }
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • sankarapandiyanS sankarapandiyan

                    @Ratzz

                           {                          
                                QDomDocument document;
                                 QDomElement root = document.createElement("OCT_TOUCH");
                                  document.appendChild(root);
                                  qDebug() <<ui->wide3ddefltbtn->text ();
                    
                                       for (int var = 0; var < ui->mwtabwidget->count(); ++var) {
                                       qDebug() << ui->mwtabwidget->tabText(var);
                    
                                     QString text = ui->mwtabwidget->tabText(var);
                                     QDomElement elemTab = document.createElement("Scanmode") ;
                                      elemTab.setAttribute("tab"+QString::number(var+1), text);
                            
                            
                            QDomElement root = document.createElement("pushbuttn_text");
                                document.appendChild(root);
                                QDomElement elemTab1  = document.createElement("ss");
                                root.appendChild(elemTab1 );
                    
                                QString text1 = ui->wide3ddefltbtn->text();
                                QDomText t = document.createTextNode(text1);
                                elemTab1 .appendChild(t);
                                root.appendChild(elemTab);
                     }
                    
                          QString filename1 = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/home/newuser/Desktop/filenamemw.xml";
                          QFile file("/home/newuser/Desktop/filenamemw.xml");
                          if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
                            qDebug() << "Open the file for writing failed";
                          } else {
                            QTextStream stream(&file);
                            stream << document.toString();
                            file.close();
                            qDebug() << "Writing is done";
                          }
                    
                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #30

                    @sankarapandiyan Can you post the WHOLE code of that method?
                    What is before

                    {                          
                                QDomDocument document;
                    

                    ?
                    Do you have a loop there?

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

                      @jsulm no no there is no loop

                      jsulmJ 1 Reply Last reply
                      0
                      • sankarapandiyanS sankarapandiyan

                        @jsulm no no there is no loop

                        jsulmJ Online
                        jsulmJ Online
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #32

                        @sankarapandiyan Actually there is:

                        for (int var = 0; var < ui->mwtabwidget->count(); ++var) {
                            qDebug() << ui->mwtabwidget->tabText(var);
                            QString text = ui->mwtabwidget->tabText(var);
                            QDomElement elemTab = document.createElement("Scanmode") ;
                            elemTab.setAttribute("tab"+QString::number(var+1), text);
                                   
                            QDomElement root = document.createElement("pushbuttn_text");
                        
                        1 Reply Last reply
                        2
                        • sankarapandiyanS Offline
                          sankarapandiyanS Offline
                          sankarapandiyan
                          wrote on last edited by
                          #33

                          @jsulm but that is for reading the tabwidget of tabs only i think !!!!!!

                          jsulmJ 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @sankarapandiyan Can you post the WHOLE code of that method?
                            What is before

                            {                          
                                        QDomDocument document;
                            

                            ?
                            Do you have a loop there?

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

                            @sankarapandiyan
                            You have missed a appendChild to the main root element.

                            --Alles ist gut.

                            sankarapandiyanS 1 Reply Last reply
                            1
                            • RatzzR Ratzz

                              @sankarapandiyan
                              You have missed a appendChild to the main root element.

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

                              @Ratzz oh really where ?!! i dnt know

                              RatzzR 1 Reply Last reply
                              0
                              • sankarapandiyanS sankarapandiyan

                                @jsulm but that is for reading the tabwidget of tabs only i think !!!!!!

                                jsulmJ Online
                                jsulmJ Online
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #36
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • sankarapandiyanS sankarapandiyan

                                  @Ratzz oh really where ?!! i dnt know

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

                                  @sankarapandiyan said in how to read the text of pushbutton in XML Qt:

                                  oh really where ?!! i dnt know

                                  Can you write the exact output you want .
                                  Write tag wise in words.
                                  may be image also helps.

                                  --Alles ist gut.

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

                                    @Ratzz
                                    <3D wide/>
                                    <Scanmode Tab1="Default"/>
                                    <Scanmode tab2="Macula"/>
                                    <Scanmode tab2="Glucoma"/>

                                    this is the output
                                    2 nd 3rd and 4th line is the tab widet of tabs ,i am using the loop there to get the tab widget of tabs(text)

                                    RatzzR 1 Reply Last reply
                                    0
                                    • sankarapandiyanS sankarapandiyan

                                      @Ratzz
                                      <3D wide/>
                                      <Scanmode Tab1="Default"/>
                                      <Scanmode tab2="Macula"/>
                                      <Scanmode tab2="Glucoma"/>

                                      this is the output
                                      2 nd 3rd and 4th line is the tab widet of tabs ,i am using the loop there to get the tab widget of tabs(text)

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

                                      @sankarapandiyan said in how to read the text of pushbutton in XML Qt:

                                      this is the output

                                      Then where should the push button needs to be placed??
                                      what is the ss tag for?

                                      --Alles ist gut.

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

                                        @Ratzz sorry wait wait going to finish my code by using QList<QPushButton*> blist = ui->frame_2->findChildren<QPushButton*>();.. with a help of @mrjj
                                        i wil post here within a minute .. thanks for your help

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

                                          finally got the output by this code ,
                                          QDomDocument document;

                                          // Making the root element
                                          QDomElement root = document.createElement("OCT_TOUCH");

                                            // Adding the root element to the docuemnt
                                            document.appendChild(root);
                                          
                                          
                                              for (int var = 0; var < ui->mwtabwidget->count(); ++var) {
                                              qDebug() << ui->mwtabwidget->tabText(var);
                                          
                                              QString text = ui->mwtabwidget->tabText(var);
                                              QDomElement elemTab = document.createElement("Scanmode") ;// + QString::number(var));
                                              elemTab.setAttribute("tab"+QString::number(var+1), text);
                                              root.appendChild(elemTab);
                                              }
                                          
                                              QList<QPushButton*> blist = ui->frame_2->findChildren<QPushButton*>();
                                              for (int cc = 0; cc < blist.count(); ++cc) {
                                              QString text = blist[cc]->text();
                                              QDomElement elemTab1 = document.createElement(/*"button"*/text) ;
                                              root.appendChild(elemTab1);
                                          

                                          thanks all especially @mrjj @Ratzz @jsulm
                                          this is the output @Ratzz
                                          <OCT_TOUCH>
                                          <Scanmode tab1="DEFAULT"/>
                                          <Scanmode tab2="MACULA"/>
                                          <Scanmode tab3="GLAUCOMA"/>
                                          <3D_DISC/>
                                          <FUNDUS_PHOTO/>
                                          <WIDE_3D/>
                                          <5LINE_CROSS/>
                                          </OCT_TOUCH>

                                          RatzzR 2 Replies 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