Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Signal in QML becomes undefined

Signal in QML becomes undefined

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 876 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SietseAchteropS Offline
    SietseAchteropS Offline
    SietseAchterop
    wrote on last edited by
    #1

    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: undefined

    How can I make this work?
    Thanks in advance,
    Sietse

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      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);
          }
      }
      
      SietseAchteropS 1 Reply Last reply
      4
      • GrecKoG GrecKo

        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);
            }
        }
        
        SietseAchteropS Offline
        SietseAchteropS Offline
        SietseAchterop
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved