QFile Readall return empty array only in Release build
-
Hi all,
I recently building an Qt application using Qtwebengine, which I want to run the javascript from an external javascript library in the QRC resources, I am able to read it and load it into the Qtwebengine in the Debug build, but when i switched to the Release build, it returns empty.Here is my code:
QFile file; QString filejs; file.setFileName(":/res/web/file.js"); file.open(QIODevice::ReadOnly); filejs = file.readAll(); ui->webView->page()->runJavaScript(QString(filejs));
I tried to print out the file js after readAll(), it is empty only in Release build.
Does anyone know why? -
Hi
Could you try to see if file is actually there ?QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
}also does file.open(..) report ok or not ?
-
Hi
Could you try to see if file is actually there ?QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
}also does file.open(..) report ok or not ?
@mrjj said in QFile Readall return empty array only in Release build:
Hi
Could you try to see if file is actually there ?QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
}also does file.open(..) report ok or not ?
The file is actually there.
file.exist() or file.open() also report fine
The Iterator also log all the files and they are present.I found out in the release build and the debug build they have different named .o files, don't know if it is because the build setting cause the application can't find the file.
Is there any way to correct address a resource file in qrc for file reading? -
@mrjj said in QFile Readall return empty array only in Release build:
Hi
Could you try to see if file is actually there ?QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
}also does file.open(..) report ok or not ?
The file is actually there.
file.exist() or file.open() also report fine
The Iterator also log all the files and they are present.I found out in the release build and the debug build they have different named .o files, don't know if it is because the build setting cause the application can't find the file.
Is there any way to correct address a resource file in qrc for file reading?@Charlez-Kwan
That is very odd.
the syntax is the way
":/res/web/file.js"what does file.size() return ?
also
- different named .o
For your files or what has ?
- different named .o
-
@Charlez-Kwan
That is very odd.
the syntax is the way
":/res/web/file.js"what does file.size() return ?
also
- different named .o
For your files or what has ?
@mrjj said in QFile Readall return empty array only in Release build:
@Charlez-Kwan
That is very odd.
the syntax is the way
":/res/web/file.js"what does file.size() return ?
also
- different named .o
For your files or what has ?
File.size() return 0 is release build, return the correct value in debug build.
in debug build, theres qrc_web.o /.cpp , but not in release build
in release build theres res_web_file_js.o/.cpp - different named .o
-
@mrjj said in QFile Readall return empty array only in Release build:
@Charlez-Kwan
That is very odd.
the syntax is the way
":/res/web/file.js"what does file.size() return ?
also
- different named .o
For your files or what has ?
File.size() return 0 is release build, return the correct value in debug build.
in debug build, theres qrc_web.o /.cpp , but not in release build
in release build theres res_web_file_js.o/.cppOk so there is nothing it just name it seems in the release.
ok that is odd with the file names. Does it do that for other file ?
Also is other file also size 0 ?Maybe its not actually linked in even i never saw that before.
- different named .o
-
Ok so there is nothing it just name it seems in the release.
ok that is odd with the file names. Does it do that for other file ?
Also is other file also size 0 ?Maybe its not actually linked in even i never saw that before.
@mrjj said in QFile Readall return empty array only in Release build:
Ok so there is nothing it just name it seems in the release.
ok that is odd with the file names. Does it do that for other file ?
Also is other file also size 0 ?Maybe its not actually linked in even i never saw that before.
I deactivated the Qt-quick compiler in the release build option and it works fine now.
-
@mrjj said in QFile Readall return empty array only in Release build:
Ok so there is nothing it just name it seems in the release.
ok that is odd with the file names. Does it do that for other file ?
Also is other file also size 0 ?Maybe its not actually linked in even i never saw that before.
I deactivated the Qt-quick compiler in the release build option and it works fine now.
@Charlez-Kwan
aha! maybe it likes js files in another way when Release mode.
Good found :) -
@Charlez-Kwan
aha! maybe it likes js files in another way when Release mode.
Good found :)@mrjj said in QFile Readall return empty array only in Release build:
@Charlez-Kwan
aha! maybe it likes js files in another way when Release mode.
Good found :)@mrjj
yes, i thought it must be some project setting because it works in debug build completely fine.
Thank you for your help! -
@mrjj said in QFile Readall return empty array only in Release build:
@Charlez-Kwan
aha! maybe it likes js files in another way when Release mode.
Good found :)@mrjj
yes, i thought it must be some project setting because it works in debug build completely fine.
Thank you for your help!@Charlez-Kwan
Np :)
Thank you for reporting back.
When someday someone else experiences this, this should help.