QML: Image not showing from resource file
Solved
QML and Qt Quick
-
With a very simple project images from a resource file are not showing on the controls.
QtCreator information
Qt Creator 11.0.3 Based on Qt 6.4.3 (GCC 10.3.1 20210422 (Red Hat 10.3.1-1), x86_64) Built on Sep 27 2023 06:36:40 From revision 68359f96a9
My Main.qml
import QtQuick import QtQuick.Window import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { width: 640 height: 480 visible: true title: qsTr("Daily Pics") header: ToolBar { height: 50 RowLayout { spacing: 20 anchors.fill: parent ToolButton { icon.source: "qrc:///images/drawer.png" } } } }
My resource.qrc
<RCC> <qresource prefix="/"> <file>images/drawer.png</file> </qresource> </RCC>
The image exists in the images folder
-
@MyNameIsRichard try less slashes :D or more simply:
right click on the drawer.png in your projects view, select: copy url,
paste that url as source, profit -
@MyNameIsRichard I think you have to give your button a height and width or use the Layout.preferredWidth properties
-
I note you are using QT6 ( I gave up when I couldn't even get a drop shadow to show on a rectangle), but along the way, I found this video; https://www.youtube.com/watch?v=UDCRQiMMiZ4 this helped me at least get images to display.
-
-
@Markkyboy That provided the solution.
Add the following to CMakeLists.txt
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON)