Error - QML Image: Cannot open: url
-
Good afternoon.
There is an error adding the image source from the resource file.
If I specify a file on disk as the source, then there is no problem.
But such an application cannot be transferred to other computers.
What's the matter?Image{ anchors.fill: parent //source: "qrc:/pixmap/dice.png" //error - qrc:/qt/qml/Game01/Dice.qml:26:17: QML Image: Cannot open: qrc:/pixmap/dice.png source: "file:E:\\QML\\Game01\\dice.png" // it's ok }
-
it works, but I don't understand why?
What's wrong with the resource file?
This works great in QWidget.and when assembling webassembly, there are no pictures again, although there is no error.
And I really want this to be cross-platform.@Anton1978 said in Error - QML Image: Cannot open: url:
it works, but I don't understand why?
What's wrong with the resource file?Because the RESOURCES parameter of
qt_add_qml_module
needs actual files and will generate the qrc automatically. It's not meant to work with .qrc files. Read the doc.This works great in QWidget.
I doubt
qt_add_qml_module
works great with QWidgets.and when assembling webassembly, there are no pictures again, although there is no error.
And I really want this to be cross-platform.That's another problem.
-
The
qrc:/pixmap/dice.png
is likely not the correct one.
Are you using CMake macroqt_add_qml_module
?. Depending on your CMake projects, the defaultRESOURCE_PREFIX
can be/qt/qml
so the url would then beqrc:/qt/qml/pixmap/dice.png
. -
Yes, I'm using qt_add_qml_module.
Here's how it's implementedqt_add_qml_module(appGame01 URI Game01 VERSION 1.0 QML_FILES Main.qml QML_FILES Game.qml QML_FILES SOURCES gamecalulate.h gamecalulate.cpp QML_FILES QML_FILES Dice.qml RESOURCES Res.qrc )
qrc:/qt/qml/pixmap/dice.png. - not worck
-
Your pixmap might be in
qrc://Game01/pixmap/dice.png
What's in Res.qrc?
Also you could see what's in your resources files with the following snippet:QDirIterator it(":/", QDirIterator::Subdirectories); while (it.hasNext()) qDebug() << it.nextFileInfo();
-
qrc://Game01/pixmap/dice.png not worck too
Res.qrc - Qt resource file, I added it manually and created a pixmap prefix in it, and later added images to the resource file.And this code not found dice.png, Res.qrc only.
@Anton1978 said in Error - QML Image: Cannot open: url:
And this code not found dice.png, Res.qrc only.
That's because the
RESOURCES
parameter inqt_add_qml_module
directly adds the listed files to the target's resources. Just list your dice.png here.
If you want to use a .qrc file use theqt_add_resources
CMake function. -
-
it works, but I don't understand why?
What's wrong with the resource file?
This works great in QWidget.and when assembling webassembly, there are no pictures again, although there is no error.
And I really want this to be cross-platform.@Anton1978 said in Error - QML Image: Cannot open: url:
it works, but I don't understand why?
What's wrong with the resource file?Because the RESOURCES parameter of
qt_add_qml_module
needs actual files and will generate the qrc automatically. It's not meant to work with .qrc files. Read the doc.This works great in QWidget.
I doubt
qt_add_qml_module
works great with QWidgets.and when assembling webassembly, there are no pictures again, although there is no error.
And I really want this to be cross-platform.That's another problem.
-
A Anton1978 has marked this topic as solved on
-
oh my god, and again
qt_add_resources(appTest05 "res" #PREFIX "/res" FILES res/cube_001_mesh.mesh res/heaven.png )
This is what I get - where are the two folders from?
And in QMLModel { id: cube objectName: "Cube" rotation: Qt.quaternion(0.707107, -0.707107, 0, 0) scale: Qt.vector3d(100, 100, 100) source: "qrc://Test05/res/cube_001_mesh.mesh" //it work materials: [ defaultMaterial_material ] }
and
environment: SceneEnvironment{ clearColor: "#222222" backgroundMode: SceneEnvironment.SkyBox lightProbe: Texture{ source: "qrc:\res\heaven.png" //not worck source: "qrc://Test05/Resources/res/heaven.png" //not worck } probeExposure: 0.75 }
I really don’t understand - now what?
-
What's your question? Why would the 2 last urls work?
Do you expext the 3 different versions to work the same?https://doc.qt.io/qt-6/qt-add-resources.html#arguments-of-the-target-based-variant
-
normally you write ":/path/to/resource" or "qrc:/path/to/ressource".
You should use a single / after qrc: not "qrc://"