QT Quick no events ("onClicked" or "onCurrentIndexChanged") work - what I am doing wrong?
-
I am new to QT Quick and have a problem what I can't solve with Google search. I hope I get here help.
My problem: I have created a QT Quick App from the template "QT Quick Application Stack". But no "onClicked" event or "onCurrentIndexChanged" event will be executed. What I am doing wrong?
Test.qml
import QtQuick 2.9 import QtQuick.Dialogs 1.2 TestForm { button.onClicked: { dialog.open() } countryComboBox.onCurrentIndexChanged: { dialog.open() } MessageDialog { id: dialog title: qsTr("this is a test") text: qsTr("test ok") function show(caption) { dialog.open(); } } }
TestForm.ui.qml
import QtQuick 2.9 import QtQuick.Controls 2.2 Page { width: 600 height: 400 property alias button: button property alias countryComboBox: countryComboBox title: qsTr("Country select") ComboBox { currentIndex: 0 id: countryComboBox x: 16 y: 12 model: ["Banana", "APPLE"] } Button { id: button x: 132 y: 102 text: qsTr("Button") } }
-
on designer inside ui.qml file ... design mode ... hover the button .... right click on mouse button ... choose "go to implementation".
without these passages your code not work. After these you find in your qml file
button.onClicked: { console.log("log completed") }
regards
I just try to write the code without use the mouse trick .... and it not work.
-
Thank you @gfxx,
I tried your method, but it still doesn't work.
I have the Stack template in use and I have added a "QT Quick UI file" with the name "TestForm". When I tried to implement this with "go to implementation" in the "TestForm" it dosen't work.
Do you have any idea why this might be?
Greetings,
Sven -
@sm-a Have you try to do sometings like these?
in your main.qml
SwipeWiew:{ /* some layout code */ YourFirstPageForm:{ /* some layout code*/ function yourfunction(){ console.log("OK these work!!") } yourqmlwidget.onClick: yourfunction() } YourSecondPageForm:{ } } /* some code for navigate*/
These still not work? I attach some image (first, second, third step png.) So you can see my sample project ....
regards
-
I try to attach my sample project ... (work to my home for techer me about qml and quick world that not know too) I am attaching my example project (which I also use to learn at home qml and quick that I do not know at all well ..). This for me works very well for what you ask ... I have problems understanding how to use tableView and qmlregistertype .... but it's another story.
These because my english is poor so with the code explain me better.
I not have the required perission .... so i use git these is my folder project
Attention: in disegn mode, navigator panel control the circle with arrow state ... if not red ... the action is not performed
I hope these help
regards
-
Hi,
I followed the same steps as you and it works for me. My project files are like this-
/tmp/test$ tree . ├── main.cpp ├── main.qml ├── qml.qrc ├── qtquickcontrols2.conf ├── TestForm.ui.qml ├── test.pro ├── test.pro.user └── Test.qml
main.qml
import QtQuick 2.12 import QtQuick.Controls 2.5 ApplicationWindow { id: window visible: true width: 640 height: 480 title: qsTr("Stack") StackView { id: stackView initialItem: "Test.qml" anchors.fill: parent } }
-
@ sm-a is not necessary the name "main" in main.qml .... you must declare it on qrc file and insert in on main.cpp. main.qml is the default name on qt designer system.
The default name is not necessary at all.... testuiform can be MyIceScream.ui.qml for example .... as said @shaan7
If you have solved your issue use "solved button"
regards