how to read the text of pushbutton in XML Qt
-
May be this way
QString text1 = ui->pushbutton1->text(); QDomText t = doc.createTextNode(text1); tag.appendChild(t);
@Ratzz i think it will work i will try thanks a lot
-
@Ratzz i think it will work i will try thanks a lot
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"; } }
-
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"; } }
@Ratzz yes it works but its repeat for three times i dont know why ! :-(
but anyway thanks all for helping me -
@VRonin yeah! i know i will try surely
-
@Ratzz yes it works but its repeat for three times i dont know why ! :-(
but anyway thanks all for helping me@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??
-
@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> -
@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>@sankarapandiyan
Its the output.
You may have pressed button 3 times?
Can you show me CODE? -
{ 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"; }
-
{ 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"; }
@sankarapandiyan Can you post the WHOLE code of that method?
What is before{ QDomDocument document;
?
Do you have a loop there? -
@jsulm no no there is no loop
-
@jsulm no no there is no loop
@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");
-
@jsulm but that is for reading the tabwidget of tabs only i think !!!!!!
-
@sankarapandiyan Can you post the WHOLE code of that method?
What is before{ QDomDocument document;
?
Do you have a loop there?@sankarapandiyan
You have missed aappendChild
to the main root element. -
@sankarapandiyan
You have missed aappendChild
to the main root element.@Ratzz oh really where ?!! i dnt know
-
@jsulm but that is for reading the tabwidget of tabs only i think !!!!!!
This post is deleted! -
@Ratzz oh really where ?!! i dnt know
@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. -
@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) -
@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)@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 thess
tag for?