Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. FileDialog : How do I configure to open a specified path...?
Forum Updated to NodeBB v4.3 + New Features

FileDialog : How do I configure to open a specified path...?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 2.3k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MSDQuick
    wrote on 26 Apr 2016, 06:23 last edited by MSDQuick
    #1

    Hello ;

    my QT QUICK context question :

    How do I configure the FileDialog to open the windows default pictures directory or a specified folder path ...?

        FileDialog {
            id: picFileDialog
            nameFilters: [ "Image files (*.jpg *.png)", "All files (*)" ]
            title: "Please choose a file"
    
            folder:"/"  <----- Code I Need
    
            onAccepted: {
                id: picFileDialog
                console.log(" ...")
            }
            onRejected: {
                console.log("Canceled")
            }
        }
    

    Thanks.
    MSD.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JordanHarris
      wrote on 26 Apr 2016, 07:28 last edited by JordanHarris
      #2

      There's 2 ways that I can think of. The first and easiest way is to use the provided shortcuts.

      FileDialog {
          //... 
          folder: shortcuts.pictures
      } 
      

      The second way would be to expose a variable containing the path from QStandardPaths in C++. This might used if you need a standard path that's not available from the shortcuts.

      QUrl picturesPath{ QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).at(0) };
      view.rootContext()->setContextProperty("picturesPath", &picturesPath);
      

      I could also imagine making a struct of some kind that acts similar to shortcuts in FileDialog, which contains members for whichever standard paths you may need in your application.

      Sorry if the code is wrong (I'm typing from my phone), but this should get the idea across.

      M 1 Reply Last reply 28 Apr 2016, 02:55
      0
      • J JordanHarris
        26 Apr 2016, 07:28

        There's 2 ways that I can think of. The first and easiest way is to use the provided shortcuts.

        FileDialog {
            //... 
            folder: shortcuts.pictures
        } 
        

        The second way would be to expose a variable containing the path from QStandardPaths in C++. This might used if you need a standard path that's not available from the shortcuts.

        QUrl picturesPath{ QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).at(0) };
        view.rootContext()->setContextProperty("picturesPath", &picturesPath);
        

        I could also imagine making a struct of some kind that acts similar to shortcuts in FileDialog, which contains members for whichever standard paths you may need in your application.

        Sorry if the code is wrong (I'm typing from my phone), but this should get the idea across.

        M Offline
        M Offline
        MSDQuick
        wrote on 28 Apr 2016, 02:55 last edited by
        #3

        @JordanHarris
        Thank you JordanHarris, I put this codes and it works fine :

         FileDialog {
        ...   
             folder: "file:///C:/Users/Admin/Pictures/"
        ...
        
        1 Reply Last reply
        1
        • J Offline
          J Offline
          JordanHarris
          wrote on 28 Apr 2016, 03:26 last edited by JordanHarris
          #4

          That'll work on that particular machine, for that user, and may be okay for testing, but you really shouldn't use a specific path like that. Did you try the shortcuts option I mentioned? The Qt Quick music player example does something similar to the second option I showed. I suspect that example might have been created before shortcuts was made available though. This is the exact code from that example:

          QQmlApplicationEngine engine;
          const QStringList musicPaths = QStandardPaths::standardLocations(QStandardPaths::MusicLocation);
          const QUrl musicUrl = QUrl::fromLocalFile(musicPaths.isEmpty() ? QDir::homePath() : musicPaths.first());
          engine.rootContext()->setContextProperty(QStringLiteral("musicUrl"), musicUrl);
          
          1 Reply Last reply
          0

          1/4

          26 Apr 2016, 06:23

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved