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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With