Results 1 to 6 of 6

Thread: selectedFilter of getSaveFileName() gives nothing under Linux

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

    Default selectedFilter of getSaveFileName() gives nothing under Linux

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selectedFilter of getSaveFileName() gives nothing under Linux

    Works perfectly fine for me on Linux with Qt 4.5.1...
    Qt Code:
    1. #include <QtGui>
    2. #include <QtDebug>
    3.  
    4. int main(int argc, char **argv){
    5. QApplication app(argc, argv);
    6. QString selectedFilter;
    7. QString fileName = QFileDialog::getSaveFileName(0,
    8. "QFileDialog::getSaveFileName()",
    9. "",
    10. QString("All Files (*);;Text Files (*.txt)"),
    11. &selectedFilter);
    12. qDebug() << fileName;
    13. qDebug() << selectedFilter;
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    $ ./x
    "/tmp/xxx.txt"
    "Text Files (*.txt)"
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: selectedFilter of getSaveFileName() gives nothing under Linux

    Do you think that it was a bug on Qt 4.5.0 and has been fixed on Qt 4.5.1 ?

    Well, I should upgrade firstly to Qt 4.5.1 and then see what happens.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selectedFilter of getSaveFileName() gives nothing under Linux

    I don't think there was such a bug. A lot of software would be broken if that was the case.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: selectedFilter of getSaveFileName() gives nothing under Linux

    I have tried with Qt 4.5.2 (the newest version coming yesterday) and such a problem doesn't occur.

    I tried back to use Qt 4.5.0, and the problem came up again.

    Not a bug ? if so, I don't know how to call such a problem

  6. #6
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selectedFilter of getSaveFileName() gives nothing under Linux

    Hi!
    I had same problem today, i think it's realy bug ;-). I rather solve it by another way (not completly same, but functional):
    Qt Code:
    1. QFileDialog dialog(this, tr("Save as ..."), editor->getFileName());
    2. dialog.setAcceptMode(QFileDialog::AcceptSave);
    3. dialog.setNameFilters(formats);
    4.  
    5. if (dialog.exec() != QDialog::Accepted) return false;
    6.  
    7. filter = dialog.selectedNameFilter();
    8. fn = dialog.selectedFiles()[0];
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Which Linux distribution is best for building compatible apps?
    By Oxidative in forum Installation and Deployment
    Replies: 8
    Last Post: 9th July 2009, 16:13
  2. Replies: 5
    Last Post: 15th January 2009, 09:03
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Deploying App on Linux
    By janus in forum Installation and Deployment
    Replies: 5
    Last Post: 6th May 2008, 21:18

Tags for this Thread

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.