How can I call a function in ui.qml files in Qt Creator

365 Views Asked by At

I created a project in Qt Design Studio and then moved it to Qt Creator. I went through the conversion steps and now I only have .ui.qml files Now I want call some functions in .ui.qml files. For example, I have a shape that I want to log a text by clicking on it. But qt creator alert me that I can not use functions or JavaScript blocks in Qt Quick UI forms.

errors in qt creator:

errors in qt creator

in Main.ui.qml :

import QtQuick 2.8

Item {
    id: main
    width: 1024
    height: 768
    
    Image {
        id: someImage
        MouseArea {
            anchors.fill: parent
            onClicked: {
                   // Here "JavaScript blocks are not supported in a Qt Quick UI 
                   // form." error occurs
            }
        }
    }
}
0

There are 0 best solutions below