woboq / qmetaobject-rs

Integrate Qml and Rust by building the QMetaObject at compile time.
MIT License
637 stars 89 forks source link

Error using inline components (qml\qqmltypedata.cpp, line 514) when a dash is in the load_file path #147

Open FuSoftware opened 3 years ago

FuSoftware commented 3 years ago

Using inline components, on Qt 5.15.2, I regularly stumble on an error :

Debug Error!

Program: ...
Module: 5.15.2
File: qml\qqmltypedata.cpp
Line: 514

ASSERT: "errors.empty()" in file qml\qqmltypedata.cpp, line 514

(Press Retry to debug the application)

This popup only shows when building for debug, and only shows up when using Rust. If I compile my code in a QML project in QtCreator, I get no errors at all.

I currently send no property to the QML context, nor expose a custom class to the QML engine.

Looking at the source, it seems it's indeed linked to the inline component.

Is it a known issue, and is there a way to mitigate it ? As the crate has no support for runtime QRC files, I'm having to declare my entire UI in a single file, and make use of inline components.

Example of an inline component :

import QtQuick 2.14
import QtQuick.Controls 2.15
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.15
import QtQuick.Window 2.14

ApplicationWindow  {
    width: 1280
    height: 960
    visible: true
    title: qsTr("DW-8P")

    component Bar: ColumnLayout {
        Text {
            text: "foo"
        }
    }

    Bar {}
}

Thanks in advance

FuSoftware commented 3 years ago

Seems like the crate doesn't like it when the paths has a dash in it. Curious to know if it's the QML engine itself that has a problem with it, or if it's somewhere else. Even stranger is that it works if the QML source doesn't contain any inline component.

// Doesn't work
engine.load_file("config/DW-8P/DW-8P.qml".into());

// Works
engine.load_file("config/DW8P/DW8P.qml".into())
ratijas commented 3 years ago

Can you elaborate, please, what do you mean by this:

the crate has no support for runtime QRC files

Sounds like a Qt bug, but I'll have to verify.

FuSoftware commented 3 years ago

What I mean is that, if I understood correctly, the qrc! macro is only evalutated at compile time, it cannot be defined at runtime. Not sure if it is a Qt bug, as it works when used with Qt C++. Maybe something with how the crate interfaces with Qt ?

ratijas commented 3 years ago

Well, with Qt's native rcc tool, you have options to either translate you resources it to *.cpp which would be compiled and baked right into your lib/bin target (which CMake handles out of the box), or to build an equivalent *.rcc resource container which can be loaded at runtime. So, it takes *.qrc XML file as an input, and produces either *.cpp for compile-time or *.rcc for run-time.

In this crate the rcc.exe is replaced by qrc!() procedural macro which runs at compile time by rustc itself, so no external tooling is needed.

I do not rule out the possibility, however, that this crate implementation may be buggy, and struggles with dashes in filenames.

Can you provide "Minimal Complete and Verifiable Example" for both C++ and Rust projects?