Results 1 to 10 of 10

Thread: setBaseUrl() problem

  1. #1
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default setBaseUrl() problem

    My directory tree is like this:
    Qt Code:
    1. root
    2. assets
    3. content
    4. skins
    5. default
    6. test
    7. main.cpp
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // I do this in test/main.cpp:
    2. view.engine()->setBaseUrl(QUrl::fromLocalFile(
    3. QCoreApplication::applicationDirPath() + "/../"));
    4.  
    5. // I do this to a QQuickView instance:
    6. setSource(QUrl::fromLocalFile("skins/default/main.qml"));
    To copy to clipboard, switch view to plain text mode 

    main.qml loads OK, but cannot reference assets in the assets subdirectory as, "assets/someimage.png", but needs to do "../../assets/someimage.png", also I cannot import as 'import "content"', but need to do 'import "../../content"', whereas I'd like to do 'import "content"'. Does there exist a workaround?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: setBaseUrl() problem

    Where is the final binary located?
    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.


  3. #3
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: setBaseUrl() problem

    In test. Do I need to write a custom filesystem provider?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: setBaseUrl() problem

    In "test" or in some "debugsomethingsomething" directory? Please check where the binary really resides. Also make sure you resolve file paths in QML using Qt.resolvedUrl().
    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.


  5. #5
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: setBaseUrl() problem

    Yes, in test, this is built on linux with the new Qt5 beta 2. On windows it usually is in test/debug.

    Qt Code:
    1. Component.onCompleted: console.log(Qt.resolvedUrl("assets/image.png"))
    To copy to clipboard, switch view to plain text mode 

    outputs

    file:///home/user/root/skins/default/assets/image.png
    Could this be a Qt5 bug?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: setBaseUrl() problem

    I'm beginning to think that setBaseUrl() does not involve resolving files from within QML itself.
    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.


  7. #7
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: setBaseUrl() problem

    For real? Did you test with QtQuick 1? A workaround might be a filesystem provider, say "assets://image.png". I've seen such a thing on the Blackberry.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: setBaseUrl() problem

    Quote Originally Posted by ugluk View Post
    For real? Did you test with QtQuick 1?
    No, only on QtQuick 2.0 since that's what you said you were using. Qt.resolvedUrl() docs claim to resolve the url relative to the QML file so the output you get is correct. One would have to check how it behaves when resolvedUrl() is not called.

    A workaround might be a filesystem provider, say "assets://image.png". I've seen such a thing on the Blackberry.
    Or an image provider.
    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
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: setBaseUrl() problem

    One more question on URLs, wysota. Does the import statement accept an URL to import from, or does the argument have to be a local pathname? What I am looking at is, whether the import statement can load a QML from a website or from a filesystem provider.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: setBaseUrl() problem

    Quote Originally Posted by ugluk View Post
    Does the import statement accept an URL to import from, or does the argument have to be a local pathname?
    If you are talking about javascript files then it can be whatever QNetworkAccessManager supports, so http URLs should be fine.

    What I am looking at is, whether the import statement can load a QML from a website or from a filesystem provider.
    I have no idea how it behaves for QML files because for QML you don't pass URLs but rather package names. You'd probably have to try with qmldir files if it works or not.
    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.


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.