PDA

View Full Version : QFileDialog::getOpenFileName() clear history



pkj
29th January 2013, 04:22
The static function of QFileDialog::getOpenFileName() QFileDialog#getOpenFileName defines a dir path for the current working directory. For the usage as:


QString filename = QFileDialog::getOpenFileName(0, tr("open file"), dirpath);

it sets the working directory as expected. However, the next time I open the dialog, the current working directory is set to last path where I picked the file from! In other words, history is being set in QFileDialog. I want to open the file dialog from the working directory I have specified, and not bother with the history. Is there a way I can do it, while keep using the convinience static function?
I can use QFileDialog as a conventional dialog function and not use the convinience function and overcome the issue, but given that there seems no way I can have native dialogs with QFileDialog, I wish to avoid its usage via the conventional dialog way.

std.approach
25th February 2013, 13:38
Hi!
try to use that solution http://www.archivum.info/qt-interest@trolltech.com/2008-12/00551/Re-(Qt-interest)-QFileDialog-Question-(SOLVED).html
or
there is a function 'void QFileDialog::setHistory ( const QStringList & paths )', but as I realized, it doesnt work
or you might create your own FileDialog with blackJack and other staff)
Best, Denis.

std.approach
27th February 2013, 11:27
correction:
the path with QSetting doesnt work
second one with QFileDialog::setHistory - doesnt work, too (as I said before).
As did I placed below:
step1. add public function to QFileDialog (yes, it should edit the Qt source)


//qfiledialog.h
void clearCurrentHistoryLocation();
implementation:


//qfiledialog.cpp
void QFileDialog::clearCurrentHistoryLocation()
{
Q_D(QFileDialog);
this->setHistory(QStringList());
d->clearCurrentHistoryLocation();
}
step2. add function to QFileDialogPrivate


//qfiledialog_p.h
void clearCurrentHistoryLocation();
implementation:


void clearCurrentHistoryLocation()
{
currentHistory.clear();
currentHistoryLocation=-1;
}
it works, I garantee that)