Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDir::searchPaths is so confusing
Forum Updated to NodeBB v4.3 + New Features

QDir::searchPaths is so confusing

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.7k 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.
  • Midori YakumoM Offline
    Midori YakumoM Offline
    Midori Yakumo
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Midori YakumoM Offline
      Midori YakumoM Offline
      Midori Yakumo
      wrote on last edited by
      #2

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

      kshegunovK 1 Reply Last reply
      0
      • Midori YakumoM Midori Yakumo

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

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

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

        Read and abide by the Qt Code of Conduct

        Midori YakumoM 1 Reply Last reply
        0
        • kshegunovK kshegunov

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

          Midori YakumoM Offline
          Midori YakumoM Offline
          Midori Yakumo
          wrote on last edited by
          #4

          @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.

          kshegunovK 1 Reply Last reply
          0
          • Midori YakumoM Midori Yakumo

            @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.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @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.

            Read and abide by the Qt Code of Conduct

            Midori YakumoM 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @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.

              Midori YakumoM Offline
              Midori YakumoM Offline
              Midori Yakumo
              wrote on last edited by
              #6

              @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

              1 Reply Last reply
              0

              • Login

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