Quantcast
Channel: Installation and Deployment
Viewing all articles
Browse latest Browse all 22112

Loop tableWidget export

$
0
0
Hopefully my last question for this case. I’ve got four QTableWidgets here. All of them contain 64 rows and 3 columns. I want to export all of them into a single XML file which should look like this: <UIS_CONFIG>     <CONFIG>         <NR_OF_UIS>64</NR_OF_UIS>     </CONFIG>     <DIGIO>         <IO>             <PIN>1</PIN>             <VAL>0</VAL>         </IO>         <IO>             <PIN>2</PIN>             <VAL>0</VAL>         </IO>         <IO>             <PIN>3</PIN>             <VAL>0</VAL>         </IO>         <IO>             <PIN>4</PIN>             <VAL>0</VAL>         </IO>           ..............     </DIGIO> </UIS_CONFIG> “PIN” is the PinNr., “VAL” is the connected key (column 3 of my table). Here’s a picture of the table (the other three are exactly the same): Now, everything’s fine. I can successfully export one of the four tables. But now I try to loop the whole thing, to export the four tables at once. Here’s what I’ve tried: void MainWindow::on_actionExport_triggered() {         QString filename = QFileDialog::getSaveFileName(                 this,                 tr("Konfig speichern"),                 QDir::currentPath(),                 tr("Konfigurationsdatei (*.xml)") );             if( !filename.isNull()) {             QFile::remove(filename);             if ( !filename.endsWith(".xml", Qt::CaseInsensitive))                 filename += ".xml";             QFile file(filename);             file.open(QIODevice::WriteOnly | QIODevice::Text);             QTextStream outPut(&file);               //QDomDocument               QDomDocument xmlDocument;             QString numberOfRows = QString::number(ui->tableWidget_5->rowCount());               QDomElement NOUElement = xmlDocument.createElement("NR_OF_UIS");             NOUElement.appendChild( xmlDocument.createTextNode(numberOfRows));               QDomElement configElement = xmlDocument.createElement("CONFIG");             QDomElement digioElement = xmlDocument.createElement("DIGIO");               QDomElement uisConfigElement = xmlDocument.createElement("UIS_CONFIG");             configElement.appendChild(NOUElement);             uisConfigElement.appendChild(configElement);             uisConfigElement.appendChild(digioElement);               QDomNode tmpNode;             QDomElement tmpElement;             QDomText tmpTxt;             QDomText tmpTxt2;               QTableWidget * pTable;               for ( int t = 0; t < 4; ++t)             {                   if ( t = 0 ) {                     pTable = ui->tableWidget_5;}                 if ( t = 1 ) {                     pTable = ui->tableWidget_6;}                 if ( t = 2 ) {                     pTable = ui->tableWidget_7;}                 if ( t = 3 ) {                     pTable = ui->tableWidget_8;}                     for( int r = 0; r < pTable->rowCount(); ++r )                 {                        QDomElement ioElement = xmlDocument.createElement("IO");                      tmpNode = digioElement.appendChild(ioElement);                      QDomNode nodePin = tmpNode.appendChild(xmlDocument.createElement("PIN"));                      QDomNode nodeVal = tmpNode.appendChild(xmlDocument.createElement("VAL"));                        tmpTxt =  xmlDocument.createTextNode(pTable->item(r,0)->data(Qt::DisplayRole).toString());                      nodePin.appendChild(tmpTxt);                        QComboBox *combo = qobject_cast<QComboBox*>(pTable->cellWidget(r,2));                      if(combo)                      {                          QString sIndex;                          sIndex = QString("%1").arg(combo->currentIndex());                          tmpTxt =  xmlDocument.createTextNode(sIndex);                          qDebug() << sIndex;                      }                        nodePin.appendChild(tmpTxt);                      nodeVal.appendChild(tmpTxt);                 }             }             xmlDocument.appendChild(uisConfigElement);               outPut << xmlDocument.toString(4);                 }   } So, here I try to loop this thing…: for ( int t = 0; t < 4; ++t)             {                   if ( t = 0 ) {                     pTable = ui->tableWidget_5;}                 if ( t = 1 ) {                     pTable = ui->tableWidget_6;}                 if ( t = 2 ) {                     pTable = ui->tableWidget_7;}                 if ( t = 3 ) {                     pTable = ui->tableWidget_8;}   ... But this does not seem to work. What can I try?

Viewing all articles
Browse latest Browse all 22112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>