где-то объявлено QSettings settings;void saveItem(QTreeWidgetItem* item){ settings.beginGroup(item->data(0, Qt::DisplayRole)); settings.setValue("1", item->data(1, Qt::DisplayRole)); settings.setValue("2", item->data(2, Qt::DisplayRole)); //и тд for(int i = 0; i < item->childCount(); i++) { QTreeWidgetItem* child = item->child(i); saveItem(child); } settings.endGroup();}voidSaveTree(){ settings.beginGroup("tree"); saveItem(topItem) for(int i = 0; i < treeWidget->topLevelItemCount(); i++) { QTreeWidgetItem* item= treeWidget->takeTopLevelItem(i); saveItem(item); } settings.endGroup();}
void Form3::writeSettings(){ QTreeWidgetItem* item; QSettings settings("Tr", "App"); //for(int i = 0; i < treeWidget->topLevelItemCount(); i++) { //QTreeWidgetItem* item= treeWidget->takeTopLevelItem(i); settings.setValue("1", item->data(0, Qt::DisplayRole)); settings.setValue("2", item->text(0)); // }}
void Form3::readSettings(){ QSettings settings("Tr", "App"); QString str = settings.value("2").toString(); m_ui.treeWidget->topLevelItem(0)->setText(0, str);}
void Form3::closeEvent(QCloseEvent *event){ writeSettings(); event->accept();}