Important: Please read the Qt Code of Conduct -

Loading JavaScript file from ressources for own WebServer

  • Hello,

    I created an own little webserver in QT to deliver a small webapp.
    Now I got a strange behaviour when testing the release version of my application.

    The html files will be delivered from a qt ressource file, so I do not have to be patient that the files exists on local hard drive.

    The html file also loads a jquery file which will be loaded from the ressources too.

    Pseudo code (very simplified):

    if (requestString == "index.html") {
       return QFile(":/html/index.html).readAll();
    if (requestString == "jquery.js") {
       return QFile(":/html/jquery.js").readAll();

    When I test the debug version everything looks fine.
    The release version is opening the jquery.js but the returned content length is always 0.

    Renaming the jquery.js to jquery.txt makes the application work again.

    Could it be that js files in ressources are associated with qml?

    Thanks for your help,

  • Lifetime Qt Champion


    What version of Qt are you using ?
    On what OS ?
    Can you trigger that behaviour with a simplified example ?

  • Hi SGaist,

    I am using Qt 5.12.4 MSVC2017 64bit on Windows 10 Pro v1903.

    A simplified example would be a little bit difficult because it is a "full" webserver, this would take too long to demonstrate.

    Do you have any ideas why the js ressource fails when loaded in release mode?
    I guess it has something to do with qml.

    Bye Tom

  • @stvtdn said in Loading JavaScript file from ressources for own WebServer:


    What is the length of the data from this statement?:


  • Well, the resource system does not treat the files any different:

    #include <QCoreApplication>
    #include <QFile>
    #include <QDebug>
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QFile html(":/html/index.html");
        QFile jquery(":/html/jquery.js");
        qInfo() << "html.size" << html.size();
        qInfo() << "jquery.size" << jquery.size();
        return a.exec();

    However, I did this as a console app. Cannot imagine other types of Qt projects would treat any different.

    The data I put in each file:

Log in to reply