Results 1 to 1 of 1

Thread: File Dialog Default Directory Not Right

  1. #1
    Join Date
    Jun 2010
    Posts
    30
    Thanks
    7

    Default Re: File Dialog Default Directory Not Right

    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?

    Qt Code:
    1. MyFileDialog *fd = new MyFileDialog;
    2.  
    3. QStringList filters;
    4. filters << "*.wav" << "*.aif";
    5. fd->setFilters(filters);
    6. fd->setDefaultSuffix(".");
    7. fd->setWindowTitle("Import Audio File");
    8. fd->setFileMode(QFileDialog::AnyFile);
    9.  
    10. QString s3 = QApplication::applicationDirPath();
    11. string s4 = s3.toStdString();
    12. size_t found = s4.find("Mixer.app");
    13. s4 = s4.substr(0, found);
    14. // fd->setDirectory(s4.c_str()); // This sets the right directory but highlights the file name?
    15. fd->show();
    16.  
    17. QStringList fileNames;
    18. if(fd->exec() == QDialog::Accepted) {
    19.  
    20. QString s1 = fd->trackLineEdit->text();
    21. bool b;
    22. unsigned int track = s1.toInt(&b, 10);
    23. std::cout << "Track: " << track << std::endl;
    24.  
    25. QString s2 = fd->startTimeLineEdit->text();
    26. unsigned int startTime = s2.toInt(&b, 10);
    27. std::cout << "Start Time: " << startTime << std::endl;
    28.  
    29. fileNames = fd->selectedFiles();
    30. if (fileNames.isEmpty()) {
    31. std::cout << "No file selected!" << endl;
    32. return;
    33. } else {
    34. for (int i = 0; i < fileNames.size(); ++i)
    35. std::cout << fileNames.at(i).toLocal8Bit().constData() << std::endl;
    36. }
    37. } else {
    38. return;
    39. }
    To copy to clipboard, switch view to plain text mode 


    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?
    Last edited by cpsmusic; 27th October 2011 at 14:09.

Similar Threads

  1. Replies: 1
    Last Post: 7th June 2011, 18:22
  2. Changing default directory of output files
    By bigbill in forum Newbie
    Replies: 1
    Last Post: 6th December 2010, 01:18
  3. Default Project Directory
    By MIH1406 in forum Newbie
    Replies: 8
    Last Post: 8th September 2009, 09:35
  4. why QFileDialog does not display the default winxp dialog?
    By mismael85 in forum Qt Programming
    Replies: 5
    Last Post: 21st March 2008, 14:39
  5. Replies: 4
    Last Post: 13th June 2007, 16:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.