QML and virtual resource paths

Our project uses a Qt resource file to make our QML files embedded into the binary and ensure that they are always available to the application, even if the source directory is not present at the computer. During startup, we refer to the main QML file using the qrc:/main.qml URL. This means that the runtime only sees the file hierarchy in the resource file, and the actual source directory of the project is not taken into account.

The other QML file has the qrc:/Button.qml URL, so Qt considers them to be in the same virtual directory and everything still works. However, if you create a QML file but forget to add it to the project's resources, Qt will be unable to load that file. Even if the file is present in ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.