I'm very new to QT and I have an application which has a QTableWidget in it and I want to add save and load option to my application. the question is how to save and load data in QTableWidget. I found this page:http://doc.qt.io/qt-5/qtwidgets-tutorials-addressbook-part6-example.html#defining-the-addressbook-class but it wasn't useful:I tried a code like this to save:
void training::on_pushButton_3_clicked()
{
QVector<QTableWidgetItem*> outvector;
for(int i = 0;i<ui->tableWidget->rowCount();i++)
for(int ii=0;i<ui->tableWidget->columnCount();ii++)
outvector.append(ui->tableWidget->item(i,ii));
QString path = QFileDialog::getSaveFileName(this,QString("Save file path"),"",QString("table (*.tbl);;All Files (*)"));
if(path.isEmpty())
return;
else{
QFile file(path);
if(!file.open(QIODevice::WriteOnly)){
QMessageBox::information(this,"Error",file.errorString());
return;
}
else{
QDataStream out(&file);
out.setVersion(QDataStream::Qt_5_11);
out<<outvector;
}
}
}
Is this right?! If it works how to load the information again; if not how to save and load data in tablewidget?
Any help would be appreciated.