[Python] The UI file error when I export .ui.qml to .py file

Discussão em 'Python' iniciado por Stack, Abril 25, 2025.

  1. Stack

    Stack Membro Participativo

    I see the answer that show the process to convert a .ui.qml file from Qt Design Studio to a .py file involves several steps(text) But I get misstake in the step of save the .qml file as .ui in Qt Creator. the mistake is “An error occurred when reading a UI file with one row and one column: Marking needs to start” ps: Qt Creator 15.0.1 Based on Qt 6.8.1 (MSVC 2022, x86_64)

    Built on Jan 22 2025 13:47:55

    From revision 0855a2e14d


    Qt Design Studio 4.7 (4.7.0) Based on Qt 6.8.2 (MSVC 2022, x86_64)

    Built on Feb 15 2025 13:18:04

    From revision bfb74e5d04

    Convert a .ui.qml file from Qt Design Studio to a .py file involves several steps: Step1. Export from Qt Design Studio: Save the file as a .qml file within Qt Design Studio. So I've been using Qt Design Studio to design a simple GUI(the project name is UIDesign). This is the Screen01.ui.qml

    /*
    This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only.
    It is supposed to be strictly declarative and only uses a subset of QML. If you edit
    this file manually, you might introduce QML code that is not supported by Qt Design Studio.
    Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files.
    */

    import QtQuick
    import QtQuick.Controls
    import UIDesign

    Rectangle {
    id: rectangle
    width: Constants.width
    height: Constants.height

    color: Constants.backgroundColor

    Button {
    id: button
    text: qsTr("Press me")
    anchors.verticalCenter: parent.verticalCenter
    checkable: true
    anchors.horizontalCenter: parent.horizontalCenter

    Connections {
    target: button
    onClicked: animation.start()
    }
    }

    Text {
    id: label
    text: qsTr("Hello UIDesign")
    anchors.top: button.bottom
    font.family: Constants.font.family
    anchors.topMargin: 45
    anchors.horizontalCenter: parent.horizontalCenter

    SequentialAnimation {
    id: animation

    ColorAnimation {
    id: colorAnimation1
    target: rectangle
    property: "color"
    to: "#2294c6"
    from: Constants.backgroundColor
    }

    ColorAnimation {
    id: colorAnimation2
    target: rectangle
    property: "color"
    to: Constants.backgroundColor
    from: "#2294c6"
    }
    }
    }
    states: [
    State {
    name: "clicked"
    when: button.checked

    PropertyChanges {
    target: label
    text: qsTr("Button Checked")
    }
    }
    ]
    }



    I've saving the Screen01.ui.qml as Screen01.qml

    **Step2:**Open in Qt Creator: Open the .qml file in Qt Creator. when I open the Screen01.qml in Qt Creator I found this message in the line "import UIDesign"

    QML module not found (UlDesign).
    Import paths:D:/0T/Tools/QtCreator/bin/qm
    For qmake projects, use the QML lMPORT PATH variable to add import paths.For Qbs projects, declare and set a qmllmportPaths property in your product to add import paths.For qmlproject projects, use the importPaths property to add import paths.For CMake projects, make sure QML IMPORT PATH variable is in CMakeCache.txt.For qmlRegister. calls, make sure that you define the Module URl as a string literal


    I'm a new user of Qt. I think the UIDesign module is not important and useful in the several steps. So I del this line to ignore this message.

    Step3: Save as .ui: Save the file again, this time using the .ui extension. This step is crucial as the .ui.qml format from Qt Design Studio is not directly compatible with the tools used to generate Python code.

    when I try to save the Screen01.qml as Screen01.ui file. This mistake occurred:

    An error occurred when reading a UI file with 1 row and 1 column: Marking needs to start


    I can not understand what error in the 1 row and 1 column. This the Screen01.ui file.

    /*
    This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only.
    It is supposed to be strictly declarative and only uses a subset of QML. If you edit
    this file manually, you might introduce QML code that is not supported by Qt Design Studio.
    Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files.
    */

    import QtQuick
    import QtQuick.Controls

    Rectangle {
    id: rectangle
    width: Constants.width
    height: Constants.height

    color: Constants.backgroundColor

    Button {
    id: button
    text: qsTr("Press me")
    anchors.verticalCenter: parent.verticalCenter
    checkable: true
    anchors.horizontalCenter: parent.horizontalCenter

    Connections {
    target: button
    onClicked: animation.start()
    }
    }

    Text {
    id: label
    text: qsTr("Hello UIDesign")
    anchors.top: button.bottom
    font.family: Constants.font.family
    anchors.topMargin: 45
    anchors.horizontalCenter: parent.horizontalCenter

    SequentialAnimation {
    id: animation

    ColorAnimation {
    id: colorAnimation1
    target: rectangle
    property: "color"
    to: "#2294c6"
    from: Constants.backgroundColor
    }

    ColorAnimation {
    id: colorAnimation2
    target: rectangle
    property: "color"
    to: Constants.backgroundColor
    from: "#2294c6"
    }
    }
    }
    states: [
    State {
    name: "clicked"
    when: button.checked

    PropertyChanges {
    target: label
    text: qsTr("Button Checked")
    }
    }
    ]
    }


    **Step4:**Convert to .py: Use the pyuic tool, which is part of PyQt or PySide, to convert the .ui file to a .py file. The command-line syntax is as follows:

    pyuic5 -o output_file.py input_file.ui


    I think the Screen01.ui is not correct. Because, in this step, the same mistake occurred:

    An error occurred when reading a UI file with 1 row and 1 column: Marking needs to start

    Continue reading...

Compartilhe esta Página