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. Loading JavaScript file from ressources for own WebServer
QtWS25 Last Chance

Loading JavaScript file from ressources for own WebServer

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 298 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.
  • S Offline
    S Offline
    stvtdn
    wrote on last edited by
    #1

    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,
    Tom

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      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
      0
      • S Offline
        S Offline
        stvtdn
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

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

          QFile(":/html/jquery.js").readAll();

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

          QFile(":/html/jquery.js").readAll();
          

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by fcarney
            #5

            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:
            jquery.js
            index.html

            C++ is a perfectly valid school of magic.

            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