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. What is the difference between ":/test.html" and "qrc:/test.html"?

What is the difference between ":/test.html" and "qrc:/test.html"?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 333 Views
  • 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.
  • F Offline
    F Offline
    fcarney
    wrote on 12 Mar 2020, 20:39 last edited by
    #1

    This is really confusing me. Some things require a "qrc:/test.txt" scheme via a QUrl. Other things like QFile want a string ":/test.txt". So I want to use one or the other, but because of QUrl and QFile I use a mix. I would like to only use "qrc:/" prefix when accessing things by wrapping it in a QUrl. But QFile won't take a QUrl and the conversions don't keep the ":/" on the front. If I set the scheme to ":" or "" the toString method kicks out an empty string.

    Why is there no simple conversion from QUrl to access qrc files for QFile? What am I missing?

                    QUrl url1("qrc:/test.html");
                    QUrl url2(":/test.html");
                    qInfo() << url1.toString();
                    qInfo() << url2.toString();
                    qInfo() << url1.toString(QUrl::RemoveScheme);
    

    Spits out:

    "qrc:/test.html"
    ""
    "/test.html"
    

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Mar 2020, 20:52 last edited by
      #2

      Hi,

      QFile represents a path on a file system. A Qt resource is a specialised filesystem hence the :/.
      QUrl represents a locator and thus requires a scheme hence the qrc:/

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • F Offline
        F Offline
        fcarney
        wrote on 12 Mar 2020, 21:01 last edited by
        #3

        What is frustrating is I have QXmlQuery with the setQuery function. This accepts a QUrl. So to feed a file from the resources I give it path like this "qrc:/query.xslt". Yet for QFile I have feed it something like this ":/test.html". So now I have some constants to access to resources using "qrc:/" and some using ":/". To convert between the two I have to do ugly string concatenation.

        My solution is pretty bad too:

        QFile file(":"+QUrl("qrc:/test.html").toString(QUrl::RemoveScheme));
        

        This at least keeps my constants consistent.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Mar 2020, 21:05 last edited by
          #4

          In that case, you might want to consider having a helper function that does that conversion so you don't have to spread that all over your code.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4

          1/4

          12 Mar 2020, 20:39

          • 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