Results 1 to 12 of 12

Thread: how to I restrict the change folder optionality in a file dialog

  1. #1
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default how to I restrict the change folder optionality in a file dialog

    I open a "save file" dialog throgh the function call QFileDialog::getSaveFileName() .........
    Now I want that the file which is to be saved should always get saved in the current file directory itself........what should I do for that?
    Thanx in advance!!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to I restrict the change folder optionality in a file dialog

    By setting a filter

  3. #3
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to I restrict the change folder optionality in a file dialog

    tbscope, I guess filter impacts only the display of the files by their extensions (this is according to the QFileDialog's documentation).
    qt_user, instead you can do something like this:
    Qt Code:
    1. do {
    2. QString filePath = QFileDialog::getSaveFileName(parent, caption, dir, filter);
    3. } while (isFilePathAcceptable(filePath));
    To copy to clipboard, switch view to plain text mode 

    where isFilePathAcceptable is your function that implements the criteria for checking whether the file path is valid. Saying "current directory" may imply different paths, so only know what a proper check should be done.
    I'm a rebel in the S.D.G.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to I restrict the change folder optionality in a file dialog

    Quote Originally Posted by lyuts View Post
    tbscope, I guess filter impacts only the display of the files by their extensions (this is according to the QFileDialog's documentation).
    I have to be honest and say I don't really know, but the documentation of the QDir filters says this:

    QDir::Dirs List directories that match the filters.
    I assume that you can set a name filter and then set it to only show the dirs that match the name filter?

  5. #5
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to I restrict the change folder optionality in a file dialog

    Quote Originally Posted by tbscope View Post
    I have to be honest and say I don't really know, but the documentation of the QDir filters says this:


    I assume that you can set a name filter and then set it to only show the dirs that match the name filter?
    That is all about QDir's filter but not QFileDialog's filter. In case of QDir it is understood that a filter influences the list of directories, but in case of QFileDialog it will co rrespondingly influence a list of files to display. But qt_user needs to restrict the list of directories, while using QFileDialog. That's why I assumed that the filter will not help him in this case.
    I'm a rebel in the S.D.G.

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to I restrict the change folder optionality in a file dialog

    I don't understand the original post. If you're asking that the file always be saved in the "current directory," I assume you mean the directory where the program was started; in that case, just set the getSaveFileName() dir parameter to "./".

    If you're asking how to always save the file in the same, fixed directory, the same approach can be taken, although you don't really need a file dialog for that; a simple dialog with a line edit asking for the filename is sufficient.

    In either of the first instances, it will always be possible for the user to navigate somewhere else with the provided file dialog. Short of reimplementing the guts of the file dialog, you can simply check the returned filename, and if it isn't in the desired directory put up a warning and reject it.

  7. #7
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to I restrict the change folder optionality in a file dialog

    Quote Originally Posted by SixDegrees View Post
    I don't understand the original post. If you're asking that the file always be saved in the "current directory," I assume you mean the directory where the program was started; in that case, just set the getSaveFileName() dir parameter to "./".
    By setting the dir to "./" you specify the starting location for QFileDialog when it is opened, but that doesn't prohibit a user to change this directory to another one and save a file there, which will mean that the file is going to be saved in the wrong location. Do you agree with that?
    I'm a rebel in the S.D.G.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: how to I restrict the change folder optionality in a file dialog

    I think you should build your own dialog instead of using QFileDialog and do not even bother the user with information it is tied to the filesystem. Just let him enter the filename and that's it.
    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.


  9. #9
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to I restrict the change folder optionality in a file dialog

    Yes; in fact, I made explicit mention of it in my post, along with a solution.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: how to I restrict the change folder optionality in a file dialog

    Quote Originally Posted by SixDegrees View Post
    Yes; in fact, I made explicit mention of it in my post, along with a solution.
    I admit I haven't read the whole thread
    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.


  11. #11
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to I restrict the change folder optionality in a file dialog

    That was in reply to lyuts, not you.

    Although I did mention your solution, as well.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: how to I restrict the change folder optionality in a file dialog

    Hmm... maybe I should switch to the threaded view of the forum
    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.


Similar Threads

  1. Save File in another Folder
    By GonzoFist in forum General Programming
    Replies: 14
    Last Post: 20th April 2010, 12:59
  2. Release folder - 1 .exe file only
    By Swankee in forum Qt Tools
    Replies: 6
    Last Post: 21st December 2009, 22:43
  3. Browse folder dialog
    By StephenR in forum Qt Programming
    Replies: 4
    Last Post: 8th September 2009, 13:16
  4. Restrict user from entering space in Save As File Name
    By jyoti kumar in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2007, 12:47
  5. Restrict user to open the same file
    By vermarajeev in forum General Programming
    Replies: 33
    Last Post: 25th May 2007, 08:15

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.