Results 1 to 5 of 5

Thread: Determining selected filter on getSaveFileName

  1. #1
    Join Date
    Sep 2006
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Determining selected filter on getSaveFileName

    I am currently wondering how you can determine which filter the user selected with using QFileDialog::getSaveFileName().

    I currently have it written as so, and have no idea how to implement it. I saw something about QFileDialog::selectedNameFilter() but would have no idea how to implement.

    Qt Code:
    1. bool VashTextEditor::saveAs()
    2. {
    3. QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), QDir::homePath(),
    4. tr("Vash Text Editor Files (*.vte);;Python (*.py);;C++ (*.cpp *.h *.cxx *.c)"));
    5. if (fileName.isEmpty())
    6. return false;
    7.  
    8. return saveFile(fileName);
    9. }
    To copy to clipboard, switch view to plain text mode 

    any help would be greatly appreciated and thanks in advance.

  2. #2
    Join Date
    Sep 2006
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Determining selected filter on getSaveFileName

    I figured it out. It turns out all along I was misreading the documentation.

  3. #3
    Join Date
    May 2008
    Posts
    24
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Determining selected filter on getSaveFileName

    I have no problem with it under Mac OS X Leopard.

    However under Linux, the problem occurs. The selectedFilter parameter does not return back what kind of filter the user choose.

    Any idea ????

  4. #4
    Join Date
    May 2008
    Posts
    24
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Determining selected filter on getSaveFileName

    At the moment I have to go around by calling no static functions.

  5. #5
    Join Date
    May 2008
    Posts
    24
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Determining selected filter on getSaveFileName

    Let me to make more clear about the problem.

    Please look at the standarddialog of Qt4's Examples and Demos, exactly in the dialog.cpp. Here is the code I mean.

    Qt Code:
    1. void Dialog::setSaveFileName()
    2. {
    3. QFileDialog::Options options;
    4. if (!native->isChecked())
    5. options |= QFileDialog::DontUseNativeDialog;
    6. QString selectedFilter;
    7. QString fileName = QFileDialog::getSaveFileName(this,
    8. tr("QFileDialog::getSaveFileName()"),
    9. saveFileNameLabel->text(),
    10. tr("All Files (*);;Text Files (*.txt)"),
    11. &selectedFilter,
    12. options);
    13.  
    14. if (!fileName.isEmpty())
    15. saveFileNameLabel->setText(fileName);
    16. }
    To copy to clipboard, switch view to plain text mode 

    The problem lies on the parameter selectedFilter which is not returning the user selected filter.

    What makes me wonder is that the problem occurs only in Linux OS, but not in Mac OS X. I don't know what happens in MS Windows.



    In my case, I need the user selected filter in order to save the file correctly.

    Such a problem does not occur if I use QFileDialog as a regular class without calling the static function. However, it is nice if I could use the static function also.


    Any kind of helps would be highly appreciated.

    Thx in advance.

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.