Important: Please read the Qt Code of Conduct -

Is there a way to use Switch Statements in QML UI files?

  • I know that you can create a separate QML file and create the javascript statements and then import the QML Item into the QML UI file, but I want to know if there is a way to directly implement switch statements and other javascript functions into QML UI files.


  • Moderators

    Hi @GoldRatio, *.ui.qml files are meant to only contain elements that are editable via the Qt Quick Designer. Switch statements are not declarative code, so they are not supported in *.ui.qml files:

    If you want, you can put everything (graphical items AND switch statements) inside a single *.qml file. This is actually how QML originally worked. *ui.qml files are a recent addition, created to support the Qt Quick Designer.

Log in to reply