Results 1 to 2 of 2

Thread: FileDialog does not open() to value of folder property

  1. #1
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default FileDialog does not open() to value of folder property

    Excerpt from AddEditEmployerView.qml...

    javascript Code:
    1. FileDialog {
    2. id: fileDialog
    3.  
    4. title: qsTr("Please choose a file")
    5. folder: employersController.picturesLocation()
    6. selectExisting: true
    7.  
    8. onAccepted: {
    9. image.source = fileDialog.fileUrl
    10. close()
    11. }
    12. onRejected: close()
    13. }
    To copy to clipboard, switch view to plain text mode 

    ...and from EmployersController.h:

    Qt Code:
    1. Q_INVOKABLE QUrl picturesLocation() {
    2. QUrl url("file:///" + QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).at(0));
    3. if (url.isEmpty())
    4. qDebug() << "Empty url!";
    5. else if (!url.isValid())
    6. qDebug() << "Invalid url!";
    7. else
    8. qDebug() << url;
    9. return url;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Fairly straight-forward, right? This prints
    QUrl( "file:///C:/Users/MyAccount/Pictures" )
    but then I see the following:
    QWindowsNativeFileDialogBase::shellItem: SHCreateItemFromParsingName(/C:/Users/My Account/Pictures)) failed ()
    As a point of interest, I am in fact opening to the Pictures Location for some reason, but if I change the location type to, for example, Documents Location and rebuild, the dialog continues to open to Pictures Location...and the error message persists but with the documents url instead. This leads me to believe that it is something to do with the url?

    The documentation of QML's url type says that,
    "When integrating with C++, note that any QUrl value passed into QML from C++ is automatically converted into a url value, and vice-versa."
    but I'm not sure where I'm going wrong.

    Any insight is appreciated. Thanks!
    Last edited by wysota; 22nd August 2013 at 07:56.

  2. #2
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: FileDialog does not open() to value of folder property

    Hmm the code seems to have disappeared and I can't edit or delete the original post.

    Excerpt from AddEditEmployerView.qml:

    Qt Code:
    1. folder: employersController.picturesLocation()
    To copy to clipboard, switch view to plain text mode 

    Excerpt from EmployersController.h:

    Qt Code:
    1. #include <QDebug>
    2. #include <QStandardPaths>
    3. #include <QUrl>
    4.  
    5. Q_INVOKABLE QUrl picturesLocation() {
    6. QUrl url("file:///" + QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).at(0));
    7. if (url.isEmpty())
    8. qDebug() << "Empty url!";
    9. else if (!url.isValid())
    10. qDebug() << "Invalid url!";
    11. else
    12. qDebug() << url;
    13. return url;
    14. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Intercept windows open folder
    By nasiroudin in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2012, 19:49
  2. Files in the project folder won't open...
    By danoc93 in forum Newbie
    Replies: 2
    Last Post: 20th January 2012, 20:46
  3. Open file/folder in finder with selection
    By anjul.chauhan in forum Qt Programming
    Replies: 0
    Last Post: 20th June 2011, 07:10
  4. Multiplateform open folder in explorer
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2011, 08:27
  5. Open FileDialog showing Back of the Widget in Mac
    By shyam prasad in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2007, 06:33

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.