Solved how to read the Selected combo box text in Qt XML
-
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 .
-
Did you read the docs?
-
For combo Value:
https://stackoverflow.com/questions/2056915/how-can-i-get-the-selected-value-out-of-a-qcomboboxcombobox->itemData(combobox->currentIndex())
-
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(); }
-
@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 -
@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
-
@TioRoy yes done
-
@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?
-
@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(); }
}
-
@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?
-
yes all are in the tab widget @Ratzz
-
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.
-
@Ratzz thanks a Lot