Problems with Open-Source Downloads read and

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

  • 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:


  • Lifetime Qt Champion


    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:/

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

  • Lifetime Qt Champion

    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.

Log in to reply