[SOLVED]can't open file from qresources
-
Hi,
did you add the resouce file to your project file? -
Any errors or warnings when building the project?
-
Did you try removing the build directory and doing a complete rebuild?
-
Can you give me a copy of that file so I can try it?
-
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;
-
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();
-
Hi,
in the
main()
; something likeint main (int argc, char *argv[]) { QApplication app(argc, argv); Q_INIT_RESOURCE(mresources); ..... }
-
@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.
@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.