Results 1 to 7 of 7

Thread: SelectFile() is returning NULL

  1. #1
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default SelectFile() is returning NULL

    Hello,
    I want to retrieve selected file name from file dialog. I am using selectfile() function for this but it is not returning the value.
    Below is the code snippet please let me know what is the problem.
    Qt Code:
    1. SavePage()
    2. {
    3. QFileDialog dialog(this);
    4. dialog.setMinimumSize(240, 320);
    5. dialog.setAcceptMode (QFileDialog::AcceptSave);
    6. dialog.resize(240,320);
    7. dialog.setConfirmOverwrite(false);
    8.  
    9. QString fileName;
    10.  
    11. if (dialog.exec())
    12. dialog.selectFile (fileName);
    13. else
    14. return;
    15.  
    16. // Open a file and Save in it
    17. QFile file(fileName);
    18. file.open(QIODevice::WriteOnly);
    19. QTextStream ts( &file);
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SelectFile() is returning NULL

    according to you code fileName is an empty string, line 9.
    QFileDialog::selectFile takes a const reference, so it should not modify fileName.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SelectFile() is returning NULL

    Which function should I used to retrieve file name of the selected file?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SelectFile() is returning NULL

    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: SelectFile() is returning NULL

    ...or use the static QFileDialog::getSaveFileName() and check if empty.

  6. #6
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SelectFile() is returning NULL

    I tried using this getSavefileName() static method but I was not able to resize it's window size. I am developing application for mobile device hence I want to resize the dialog window as per my device resolution.

  7. #7
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SelectFile() is returning NULL

    Thanks!! Problem is solved.

Similar Threads

  1. QSqlTableModel and NULL
    By karas in forum Qt Programming
    Replies: 0
    Last Post: 9th February 2009, 12:55
  2. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18
  3. checking for null
    By drkbkr in forum General Programming
    Replies: 6
    Last Post: 13th March 2006, 21:54

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.