Solved how to read the text of pushbutton in XML Qt
-
i have done something but it doesnt work ,This is my code
void MainWindow::on_okbutn_clicked() { QDomDocument document; QDomElement root = document.createElement("pushbuttn_text"); QString text1 = ui->pushbutton1->text(); QDomElement elemTab1 = document.createElement("ss"); elemTab1.setAttribute(QString::data(text1); //elemTab.appendChild( document.createTextNode( text)) root.appendChild(elemTab1); 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"; }
in this code writing is done properly ,and reading is the problrm i think ,
and this is my error//error: no matching function for call to 'QString::data(QString&)'~~
i think the problem is in setting attribute i dnt know how to resolve if anybody knows tel me pls.
Thanks in advanzZ.....
-
@sankarapandiyan said in how to read the text of pushbutton in XML Qt:
elemTab1.setAttribute(QString::data(text1);
Please read the documentation: http://doc.qt.io/qt-5/qstring.html#data
First: data() is not static, second data() takes no parameters.
So, it should beelemTab1.setAttribute(text1.data());
But actually there is no need to convert QString to char*, so
elemTab1.setAttribute(text1);
-
@jsulm thanks a lot
-
So if your issue is solved, please mark this topic as SOLVED too. Thanks
-
@aha_1980 nop its under process..
please try to resolve if yu can
Thanks in Advance -
@aha_1980 i'll do aftr i completed
-
So what's your problem now? Did you try @jsulm's suggestion? Do you get another error?
-
@aha_1980 yes same error i got it repeatdly .@jsulm gave the document to read ,now i am doing that.
QDomDocument document; QDomElement root = document.createElement("pushbuttn_text"); QString text1 = ui->pushbutton1->text(); QDomElement elemTab1 = document.createElement("ss"); elemTab1.setAttribute(text1);
//elemTab.appendChild( document.createTextNode( text))
root.appendChild(elemTab1);
and this is my code
-
setAttribute
should take 2 argument? -
@Ratzz nop only one it want to take
-
@Ratzz nop only one it want to take
-
@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? -
@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. -
@jsulm oh sry for my wrong answer
is it possible to do without attribute !coz i want to read one paramtr only -
yes but using
QDomText
But it creates the text node. -
@Ratzz by directly reading ??
-
@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, "");
-
@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
-
@Ratzz thanks a lot
-
May be this way
QString text1 = ui->pushbutton1->text(); QDomText t = doc.createTextNode(text1); tag.appendChild(t);