PDA

View Full Version : File Dialog Default Directory Not Right



cpsmusic
27th October 2011, 13:09
Hi,

I'm developing an application that requires a custom file dialog.

Because developing the custom file dialog was tricky I did it in a test application that just contained the file dialog. This is working properly.

I've now added the custom file dialog to my main project however when I open the custom file dialog it opens and displays the contents of the directory of the test application not the new application.

How is this happening? From what I can see, there's nothing in my code that's setting any default directory.

Also, if I try setting the file dialog's default directory using setDirectory the LineEdit containing the file name is shown as a drop down menu containing the directory (i.e. it looks like it's been selected). This only happens the first time the dialog is opened. Why is this being selected and how can I stop it happening?



MyFileDialog *fd = new MyFileDialog;

QStringList filters;
filters << "*.wav" << "*.aif";
fd->setFilters(filters);
fd->setDefaultSuffix(".");
fd->setWindowTitle("Import Audio File");
fd->setFileMode(QFileDialog::AnyFile);

QString s3 = QApplication::applicationDirPath();
string s4 = s3.toStdString();
size_t found = s4.find("Mixer.app");
s4 = s4.substr(0, found);
// fd->setDirectory(s4.c_str()); // This sets the right directory but highlights the file name?
fd->show();

QStringList fileNames;
if(fd->exec() == QDialog::Accepted) {

QString s1 = fd->trackLineEdit->text();
bool b;
unsigned int track = s1.toInt(&b, 10);
std::cout << "Track: " << track << std::endl;

QString s2 = fd->startTimeLineEdit->text();
unsigned int startTime = s2.toInt(&b, 10);
std::cout << "Start Time: " << startTime << std::endl;

fileNames = fd->selectedFiles();
if (fileNames.isEmpty()) {
std::cout << "No file selected!" << endl;
return;
} else {
for (int i = 0; i < fileNames.size(); ++i)
std::cout << fileNames.at(i).toLocal8Bit().constData() << std::endl;
}
} else {
return;
}


Added after 29 minutes:

I've restarted my IDE (Xcode) and it seems to have fixed the problem. Maybe it was something to do with remembering recent folders?