[SOLVED]can't open file from qresources
-
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.
-
hi,
so you could try to use an alias
<RCC> <qresource prefix="/plane"> <file alias="j3pipercub.obj">j3pipercub.obj</file> </qresource> </RCC>
@mcosta Ok, the code that copies the content from file to file2 works. The new file on the filesystem has the correct content. So the bytearray is not full of zeros. But output via qDebug() doesn't work. The system's locale is English so this should work.
-
I'm Using Qt 6.5.2 and had the same issue and after an hour of digging and testing all your solutions i did some digging on the build folder and i saw this:
in <QBuild_Dir>/<cmake_project_name>/<module_name>_qml_module_dir_map.qrc
<RCC> <qresource prefix="/"> <file alias="/<<<cmake_project_name>>>"><<<QBuild_Dir>>>/<<<cmake_project_name>>></file> </qresource> </RCC>
so there is an alias for the resource!
to use the resource on my C++ code i had to add it to the beginning of the resource path like
before: ":/assets/img.svg" after ":/<cmake_project_name>/assets/img.svg
and it works 👌