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.
  • RatzzR Ratzz

    @sankarapandiyan

    setAttribute should take 2 argument?

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

    @Ratzz nop only one it want to take

    RatzzR 1 Reply Last reply
    0
    • RatzzR Ratzz

      @sankarapandiyan

      setAttribute should take 2 argument?

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

      @Ratzz nop only one it want to take

      jsulmJ 1 Reply Last reply
      0
      • sankarapandiyanS sankarapandiyan

        @Ratzz nop only one it want to take

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

        @sankarapandiyan
        You want to take one attribute ??
        Did you see document ? http://doc.qt.io/archives/qt-4.8/qdomelement.html#setAttribute
        What is the error now?

        --Alles ist gut.

        sankarapandiyanS 1 Reply Last reply
        4
        • sankarapandiyanS sankarapandiyan

          @Ratzz nop only one it want to take

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

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

          nop only one it want to take

          This is wrong.
          setAttribute takes two arguments as you can see in documentation.
          A XML attribute has a name and a value, that's why setAttribute has two parameters.

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

          sankarapandiyanS 1 Reply Last reply
          2
          • jsulmJ jsulm

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

            nop only one it want to take

            This is wrong.
            setAttribute takes two arguments as you can see in documentation.
            A XML attribute has a name and a value, that's why setAttribute has two parameters.

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

            @jsulm oh sry for my wrong answer
            is it possible to do without attribute !coz i want to read one paramtr only

            RatzzR jsulmJ 2 Replies Last reply
            0
            • sankarapandiyanS sankarapandiyan

              @jsulm oh sry for my wrong answer
              is it possible to do without attribute !coz i want to read one paramtr only

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

              @sankarapandiyan

              yes but using QDomText
              But it creates the text node.

              --Alles ist gut.

              sankarapandiyanS 1 Reply Last reply
              0
              • RatzzR Ratzz

                @sankarapandiyan

                yes but using QDomText
                But it creates the text node.

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

                @Ratzz by directly reading ??

                RatzzR 1 Reply Last reply
                0
                • sankarapandiyanS sankarapandiyan

                  @jsulm oh sry for my wrong answer
                  is it possible to do without attribute !coz i want to read one paramtr only

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

                  @sankarapandiyan I don't understand you: setAttribute sets an attribute, it does not read anything. So, what do you want to do?
                  If your attribute does not have a value you can pass empty string as value:

                  elemTab1.setAttribute(text1, "");
                  

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

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

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

                    If your attribute does not have a value you can pass empty string as value:

                    sure....i will try Thanks a lot

                    1 Reply Last reply
                    0
                    • RatzzR Ratzz

                      @sankarapandiyan
                      You want to take one attribute ??
                      Did you see document ? http://doc.qt.io/archives/qt-4.8/qdomelement.html#setAttribute
                      What is the error now?

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

                      @Ratzz thanks a lot

                      1 Reply Last reply
                      0
                      • sankarapandiyanS sankarapandiyan

                        @Ratzz by directly reading ??

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

                        @sankarapandiyan

                        May be this way

                            QString text1 = ui->pushbutton1->text();
                            QDomText t = doc.createTextNode(text1);
                            tag.appendChild(t);

                        --Alles ist gut.

                        sankarapandiyanS 1 Reply Last reply
                        3
                        • RatzzR Ratzz

                          @sankarapandiyan

                          May be this way

                              QString text1 = ui->pushbutton1->text();
                              QDomText t = doc.createTextNode(text1);
                              tag.appendChild(t);
                          sankarapandiyanS Offline
                          sankarapandiyanS Offline
                          sankarapandiyan
                          wrote on last edited by
                          #21

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

                          RatzzR 1 Reply Last reply
                          0
                          • 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

                                          • Login

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