I am using QT
in my C++
application. I know that when I use QFileDialog
, the history is saved in the registry. Suppose I have multiple instances of QFileDialog
within the application. Can I save the history for each instance separately? As far as I checked, it seems that same registry entry is updated for each instance.
Asked
Active
Viewed 193 times
5

Jackzz
- 1,417
- 4
- 24
- 53
1 Answers
2
You could use different QSettings entry for each QFileDialog instance, with that you manage your history lenght 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();
}

Bastien Thonnat
- 563
- 4
- 9
-
Can you please help with a small example – Jackzz Oct 12 '17 at 10:10
-
You could follow the Qt documention with their basic usage http://doc.qt.io/qt-5/qsettings.html#basic-usage – Bastien Thonnat Oct 12 '17 at 10:28
-
After the basic usage you could use section foreach QFileDialog for example http://doc.qt.io/qt-5/qsettings.html#section-and-key-syntax – Bastien Thonnat Oct 12 '17 at 10:29
-
And for the array serialization you could use beginReadArray and beginWritteArray http://doc.qt.io/qt-5/qsettings.html#beginReadArray – Bastien Thonnat Oct 12 '17 at 10:31