Loading JavaScript file from ressources for own WebServer
-
wrote on 6 Sept 2019, 11:52 last edited by
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 -
Hi,
What version of Qt are you using ?
On what OS ?
Can you trigger that behaviour with a simplified example ? -
wrote on 9 Sept 2019, 15:17 last edited by
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
-
wrote on 9 Sept 2019, 15:34 last edited by
@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();
-
wrote on 9 Sept 2019, 15:46 last edited by fcarney 9 Sept 2019, 15:48
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
5/5