[SOLVED]can't open file from qresources
-
wrote on 18 Apr 2015, 17:41 last edited by Hamed
Hi.
I can't open a file that I added to my .qrc file.
here is my .qrc file :
<RCC>
<qresource prefix="/plane">
<file>j3pipercub.obj</file>
</qresource>
</RCC>and this is how I call this file :
mesh = load_object(":/plane/j3pipercub.obj"); -
wrote on 18 Apr 2015, 17:43 last edited by
Hi,
did you add the resouce file to your project file? -
wrote on 18 Apr 2015, 17:44 last edited by
yes this is how I did that :
RESOURCES = mresources.qrc -
wrote on 18 Apr 2015, 17:48 last edited by
Any errors or warnings when building the project?
-
wrote on 18 Apr 2015, 17:50 last edited by
No, It just not load that .obj file.
I can load it by address in my pc but can't load it from resources. -
wrote on 18 Apr 2015, 17:52 last edited by
Did you try removing the build directory and doing a complete rebuild?
-
wrote on 18 Apr 2015, 17:54 last edited by
No, I try it now.
-
wrote on 18 Apr 2015, 17:59 last edited by
Did it.
Still doesn't work! -
wrote on 18 Apr 2015, 18:10 last edited by
Can you give me a copy of that file so I can try it?
-
wrote on 18 Apr 2015, 18:12 last edited by
sure, how can I do that?
-
wrote on 18 Apr 2015, 18:39 last edited by
The file works for me. Please try this in your
load_object()
function:QFile file(":/plane/j3pipercub.obj"); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { qDebug() << "file read error"; return; } const QByteArray ba = file.readAll(); file.close(); const QString s( ba ); qDebug() << s;
-
wrote on 18 Apr 2015, 19:17 last edited by
Ok, let's see if we can copy the file's content to another file:
QFile file(":/plane/j3pipercub.obj"); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { qDebug() << "file read error"; return; } const QByteArray ba = file.readAll(); file.close(); QFile file2("/home/pw/piper.obj"); // +++++ ADJUST PATH ++++++ if (!file2.open(QIODevice::WriteOnly)) { qDebug() << "file write error"; return; } qDebug() << file2.write(ba); file2.close();
-
wrote on 18 Apr 2015, 19:21 last edited by
HI,
have you used
Q_INIT_RESOURCE
to initialize the resource?? -
wrote on 18 Apr 2015, 19:22 last edited by
No! where should I initialize it?
-
wrote on 18 Apr 2015, 19:24 last edited by
Hi,
in the
main()
; something likeint main (int argc, char *argv[]) { QApplication app(argc, argv); Q_INIT_RESOURCE(mresources); ..... }
-
Hi,
in the
main()
; something likeint main (int argc, char *argv[]) { QApplication app(argc, argv); Q_INIT_RESOURCE(mresources); ..... }
wrote on 18 Apr 2015, 19:27 last edited by -
wrote on 18 Apr 2015, 19:34 last edited by
@Wieland
Q_INIT_RESOURCE
is needed if the resource is not embedded in the application or on some platformNormally, when resources are built as part of the application, the resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro is necessary on some platforms for resources stored in a static library.
-
@Wieland
Q_INIT_RESOURCE
is needed if the resource is not embedded in the application or on some platformNormally, when resources are built as part of the application, the resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro is necessary on some platforms for resources stored in a static library.
wrote on 18 Apr 2015, 19:36 last edited by A Former User@mcosta Things are a bit strange here. Reading from the resource works. In the code I posted above there is the bytearray ba and it has the correct size, but it contains only null bytes. But only on Hamed's computer! Works on mine. I don't get it.
-
wrote on 18 Apr 2015, 19:37 last edited by
hi,
so you could try to use an alias
<RCC> <qresource prefix="/plane"> <file alias="j3pipercub.obj">j3pipercub.obj</file> </qresource> </RCC>
6/23