Solved Signal in QML becomes undefined
-
Hello list,
In my pyqt5 QML-app (5.15.2) I am struggling get rid of the deprecation mentioned below.
Here a very simple QML example that shows the deprecation problem.Item { RowLayout { id: sessionId Connections { target: crew_mpl onSessionsig: { console.log(sessig); } ....... } } }
The target is created in my main.py:
gd.crewPlots = CrewForm() gd.context.setContextProperty("crew_mpl", gd.crewPlots)
There also is the following signal:
sessionsig = pyqtSignal(list, arguments =['sessig'])
The warning that I get is:
QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) <I try to solve this by following the advice and put my code in a different function as per another advice that I found.
I do this in 2 steps.Item { RowLayout { id: sessionId function mysig (sessig) { console.log(sessig); } Connections { target: crew_mpl onSessionsig: { mysig(sessig); }}}}
This works fine, the value of sessig is printed, but when I use the new syntax: function onSessionsig () {}
Then I get the error:
qml: undefinedHow can I make this work?
Thanks in advance,
Sietse -
That's not how the new syntax work. You should put the function definition in the
Connections
block.Old:
Connections { target: crew_mpl onSessionsig: { console.log(sessig); } }
New:
Connections { target: crew_mpl function onSessionsig (session_sig) { // you can use an arbitrary parameter name, only the name of the function has to match on<SignalName> console.log(session_sig); } }
-
That's not how the new syntax work. You should put the function definition in the
Connections
block.Old:
Connections { target: crew_mpl onSessionsig: { console.log(sessig); } }
New:
Connections { target: crew_mpl function onSessionsig (session_sig) { // you can use an arbitrary parameter name, only the name of the function has to match on<SignalName> console.log(session_sig); } }
-
@GrecKo Thanks, solved!
I missed that the arguments are the signals. That's what you get when you google for answers instead of properly reading the documentation....
Regards, Sietse