Adding SVG to resource with alias and referencing in QML
-
@SPlatten it's not really compile able, is it ?
I don't have your *pro, nor your main.cpp file, nor the folder structure you claim to have.also giving your Image a width and height does help, because its super tiny without it
wrote on 23 Sept 2022, 07:08 last edited by SPlattenThis post is deleted! -
@SPlatten said in Adding SVG to resource with alias and referencing in QML:
Are they ?
They are relevant to have a compilable example...
-
@SPlatten said in Adding SVG to resource with alias and referencing in QML:
Are they ?
They are relevant to have a compilable example...
wrote on 23 Sept 2022, 07:28 last edited by SPlattenThis post is deleted! -
wrote on 23 Sept 2022, 12:48 last edited by SPlattenThis post is deleted!
-
wrote on 23 Sept 2022, 13:25 last edited by
simply:
source: "/images/stale.svg" -
wrote on 23 Sept 2022, 13:30 last edited byThis post is deleted!
-
wrote on 23 Sept 2022, 13:34 last edited byThis post is deleted!
-
wrote on 23 Sept 2022, 13:37 last edited by SPlattenThis post is deleted!
-
wrote on 23 Sept 2022, 13:46 last edited by JoeCFD
@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 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.wrote on 23 Sept 2022, 13:52 last edited by SPlattenThis post is deleted! -
wrote on 23 Sept 2022, 13:54 last edited by JoeCFD
@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 }
-
@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 }
wrote on 23 Sept 2022, 13:58 last edited byThis post is deleted! -
wrote on 26 Sept 2022, 07:37 last edited by SPlatten
@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.
-
@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.
wrote on 26 Sept 2022, 11:52 last edited byThis post is deleted! -
@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.
wrote on 26 Sept 2022, 13:58 last edited by JoeCFDCreate at least two qrc files: one for images and one for qml. Better not to mix them up.
26/33