Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved QFileDialog

    General and Desktop
    qfiledialog
    3
    3
    1018
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      GrahamL last edited by

      Hi
      Does anyone know how to use QFileDialog to display only directories for which the user has permission to create files in?

      I don't think it is possible but if you know a method I'd love to hear it!

      Thanks

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        There's no reliable way to say if a directory is writable before you actually try to write to it (you can definitely say it's not writable but you can only tell with some probability that it is writable). It would be unreasonable to try to write to every directory so there's no such mode in QFileDialog.
        On top of that QFileDialog uses native dialog in some cases and that feature is not usually present in it either.

        So I'm afraid you're out of luck.

        1 Reply Last reply Reply Quote 0
        • R
          rturrentine last edited by

          One approach we used was to use the directoryEntered signal from the QFileDialog along with a custom proxy filter to handle it. The proxy contained a member variable for the last known good folder. Example code:

          void MyProxyModel::DirectoryEntered( const QString& Dir )
          {
          QDir CurrentDir( Dir );

          // If directory has no contents, reject the change. The isReadable() property is not reliable for some reason, as
          // it permits "opening" directories that the user has no permissions for (the result is no entries in the dialog).
          if( CurrentDir.entryList().size() == 0 )
          {
          CurrentDir = m_LastGoodDir;
          m_pFileDialog->setDirectory( CurrentDir );
          }

          m_LastGoodDir = CurrentDir;
          }

          1 Reply Last reply Reply Quote 0
          • First post
            Last post