History of Multiple Instances of QFileDialog

I am using QT in a C++ application. I know that when I use QFileDialog , the history is stored in the registry. Suppose there are several instances of QFileDialog in the application. Can I save history for each instance separately? As far as I checked, it seems that the same registry entry is being updated for each instance.

+5
source share
1 answer

You can use different QSettings entries for each QFileDialog instance as you control your history by length and location.

something like that

 void callFileDialog(QLinkedList<QString> & fileDialogHistory) { QString fileName = QFileDialog::getOpenFileName(Q_NULLPTR, "Open File", QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); if(!fileName.isNull()){ fileDialogHistory << fileName; } } void saveFileDialogHistory(QLinkedList<QString> & fileDialogHistory, QString fileDialogHistoryName = "History_Default") { QSettings settings; settings.beginWriteArray(fileDialogHistoryName); int index = 0; for (QLinkedList<QString>::iterator it = fileDialogHistory.begin(); it != fileDialogHistory.end(); ++it){ settings.setArrayIndex(index); settings.setValue("filePath", QFileInfo(*it).filePath()); index++; } settings.endArray(); } 
+2
source

Source: https://habr.com/ru/post/1272544/


All Articles