I see the issue with your QML enum usage. In QML, you can't directly use an enum as a parameter type the way you're trying to do. Here's how to fix it:
Solution 1: Use int as the parameter type while keeping the enum:
qml
enum States { State0, State1, State2 }
function getSomething(id: int): string {
if (id === States.State0) return "This is State0";
if (id === States.State1) return "This is State1";
if (id === States.State2) return "This is State2";
return "Unknown state";
}
Solution 2: Define the enum in a more QML-friendly way:
// In a separate file, e.g., States.qml
pragma Singleton
import QtQml 2.15
QtObject {
readonly property int State0: 0
readonly property int State1: 1
readonly property int State2: 2
}
// Then in your main file:
import "path/to/States.qml" as States
function getSomething(id: int): string {
if (id === States.State0) return "This is State0";
// etc.
}
The key point is that in QML, enums are essentially integers under the hood, so you need to use id: int as the parameter type. The enum values themselves can still be used for comparison inside the function.
Hope this helps!