Adding SVG to resource with alias and referencing in QML
-
@SPlatten I see. All of my images have alias. Therefore, no qrc: is needed anywhere. It is good you drop it as well without alias.
I still use qrc for qml files since they do not have alias
resources/qml/main.qml: source: "qrc:/qml/MainScreen.qml"
resources/qml/main.qml: source: "qrc:/qml/SplashScreen.qml"
I will try to remove it and let you know.Confirmed: qrc is not needed even when resource files do not have alias. qrc: can be dropped completely.
But not sure why Qt did this. The code with or without qrc: should compile
In Qt6 qml module version numbers are dropped. I am using Qt 5.15.2. -
@SPlatten what is your Qt version? Is this on Linux?
check the file path in your compiled qrc_images.cpp. All your images are compiled into this file. This is my setting.<RCC> <qresource prefix="/res"> <file alias="background">images/SplashBackground.png</file> </qresource> </RCC> Image { /* background image works */ anchors.centerIn: parent source: "/res/background" width: parent.width height: parent.height }
-
@JoeCFD , I decided to create a simple application to experiment with the resources. I used the same SVG file. The resource file:
<RCC> <qresource prefix="/"> <file alias="stale.svg">stale.svg</file> <file>mainWindow.qml</file> </qresource> </RCC>
In the mainwindow:
void MainWindow::paintEvent(QPaintEvent *pobjEvt) { Q_UNUSED(pobjEvt); QPainter objPainter(this); QImage* pobjImage(new QImage(":/stale.svg")); bool blnIsNull(pobjImage->isNull()); qDebug() << QString("Image isNull: %1").arg(((blnIsNull == true) ? "Yes" : "No")); objPainter.drawImage(10, 10, *pobjImage); }
This works absolutely fine and the iamge is displayed correctly. I will not try to use this to figure out why the original isn't working.