QDir::searchPaths is so confusing



  • I want to unify the namespace of resource files out of qrc in my application so I decide to use assets: prefix by QDir::setSearchPath, it's backend is QAbstractFileEngineHandler . This schema/prefix works with QFile things (QFile, QFileInfo, QIcon, QImage...) and Android Assets (by QAndroidAssetsFileEngineHandler), but not with QUrl things (QtQuick, QtQml, ~Engine, blablabla), so confusing things happen like http://stackoverflow.com/questions/18309061/how-to-deploy-qt5-qml-plugin-to-android
    Is there any workaround to unify SearchPath and Url?



  • Ugly workaround: ```
    #define UURL(url) (QNetworkAccessManager().supportedSchemes().contains(QUrl(url).scheme())?QUrl(url):QFileInfo(url).absoluteFilePath())


  • Qt Champions 2016

    @Midori-Yakumo
    How do you pass the URI to the QUrl? It should be working with "qrc://" if I recall correctly.



  • @kshegunov yes QUrl works with "qrc://" and QDir works with ":" , I just intend to create something like: "myscheme0://", "myscheme1://" however I found it hard to realize, the only choices are qrc and assets, however there are still bugs in them.


  • Qt Champions 2016

    @Midori-Yakumo
    I don't think what you're trying to do is possible. URI's are a little more than a path, they contain a schema and are parsed according to that schema, so setting search paths for QUrl doesn't make much sense.



  • @kshegunov "URI's are a little more than a path" => searchpath scheme can be one subset of URL scheme. What I want to do is coding with my single scheme regardless of different location of my resources, wherever they are in local files, qrc resource or Android assets (even from web, I hope).
    For example, when declaring QIcon("assets:/app_icon.png") with:

    • addSearchPath("assets", "app/resource"); on desktop it can be loaded from a local file.

    • addSearchPath("assets", ":/icon"); it can be loaded from qrc

    • nothing; it can be loaded from apk in Android


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.