Aliases not working when connecting ui file with logic in separate qml file
-
Hello,
I want to integrate C++ with QML and implement some logic in a separate file using alias. For some reason I can't make that work. I am making a mobile app, using the QT Quick - Stack template and it kinda looks like the aliases are not working at all for me. I've tried to create a simple example to verify where's the problem and it's not working either. Here is the example:G.qml
import QtQuick 2.4 import QtQuick.Controls 2.12 GForm{ button.onClicked: Qt.quit()}GForm.ui.qml
import QtQuick 2.4 import QtQuick.Controls 2.12 Item { width: 400 height: 400 property alias button: button Button { id: button x: 167 y: 149 text: qsTr("Button") } }main.qml
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") GForm{} }Qt Creator screenshot.
The button in the example doesn't do anything. If I however do this:GForm.ui.qml
... Button { id: button x: 167 onClicked: Qt.quit() //HERE y: 149 text: qsTr("Button") } ...It works but with some warnings that Functions are not supported in a Qt Quick UI form
Am I misunderstanding something? Do I have to enable or import something more?
Any help is much appreciated! Have a nice day! -
I was able to fix it after all. The problem was that I assumed that when having ui.qml and .qml file, they were already connected (nameForm.ui.qml and name.qml). What needs to be done is to use the .qml file to display the elements and put the .ui.qml inside.
Like this:main.qml
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") //*GForm{} WRONG*/ G{} }