C++ (Qt)void MainWindow::writeset(){ AppFileName=qApp->applicationDirPath()+"\\rms.ini"; QSettings set(AppFileName,QSettings::IniFormat); set.setValue("ED",ui->lineEdit->text()); set.setValue("ed2",ui->lineEdit_2->text()); set.beginWriteArray("Table",2); for (int i=0;i<ui->tableWidget->rowCount();i++) { for (int j=0;j<ui->tableWidget->columnCount();j++) { set.setArrayIndex(i); set.setValue("it",ui->tableWidget->item(i,j)->text()); //set.setValue("col",j); } } set.endArray();}
C++ (Qt)settings.setValue("Table/ColumnCount", table->columnCount();settings.setValue("Table/RowCount", table->rowCount();for (int i = 0; i < table->rowCount(); i++) for (int j = 0; j < table->columnCount(); j++) settings.setValue(QString("Table/Row_%1_Column_%2").arg(i).arg(j), table->item(i, j)->text());
void MainWindow::writeset(){ AppFileName=qApp->applicationDirPath()+"\\rms.ini"; QSettings set(AppFileName,QSettings::IniFormat); set.setValue("ED",ui->lineEdit->text()); set.setValue("ed2",ui->lineEdit_2->text()); set.setValue("Table/ColumnCount", ui->tableWidget->columnCount()); set.setValue("Table/RowCount", ui->tableWidget->rowCount()); for (int i = 0; i < ui->tableWidget->rowCount(); i++) for (int j = 0; j < ui->tableWidget->columnCount(); j++) set.setValue(QString("Table/Row_%1_Column_%2").arg(i).arg(j), ui->tableWidget->item(i, j)->text());}
C++ (Qt)Q_ASSERT( ui->tableWidget->item(i, j) );
void MainWindow::readset(){ AppFileName=qApp->applicationDirPath()+"\\rms.ini"; QSettings set(AppFileName,QSettings::IniFormat);ui->lineEdit->setText(set.value("ED","no").toString());ui->lineEdit_2->setText(set.value("ed2","NO2").toString());for (int i = 0; i < ui->tableWidget->rowCount(); i++){ for (int j = 0; j < ui->tableWidget->columnCount(); j++) { //ui->tableWidget->setItem(i,j,QTableWidgetItem(set.value(QString("Table/Row_%1_Column_%2").arg(i).arg(j)),0)); ui->tableWidget->item(i,j)->setData(0,(set.value(QString("Table/Row_%1_Column_%2").arg(i).arg(j)),0)); } }}
void MainWindow::readset(){...for (int i = 0; i < ui->tableWidget->rowCount(); i++){ for (int j = 0; j < ui->tableWidget->columnCount(); j++) { ui->tableWidget->setItem( i, j, new QTableWidgetItem( set.value( QString("Table/Row_%1_Column_%2").arg(i).arg(j) ).toString(), 0 ) ); }}}