Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is it possible to make a Connections in a QmlTimer component ?



  • Hi,

    I'm trying to connect a signal from an Item to a Timer using Connections.

    My code fails when I try to run it with the following error PathToMyProject/main.qml:21 Cannot assign to non-existent default property

    If I replace the Timer component by an Item component everything works fine.

    Here is my code:

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    import QtQuick.Window 2.2
    import QtQml 2.12
    
    
    ApplicationWindow{
    	id: root
    	width: 500
    	height: 500
    	visible: true
    
    	Item {
    		id: itemId
    		signal mySignal()
    	}
    
    	Timer { // Replacing the Timer component by an Item component does not trigger any error
    		id: timerId
    		property int nbr: 13
    		Connections // This is the line 21
    		{
    			target: itemId
    			onMySignal: timerId.nbr = 42;
    		}
    	}
    
    	Column {
    		Button { text: "emit signal"; onClicked: itemId.mySignal(); }
    		Button { text: "display nbr"; onClicked: console.log(timerId.nbr); }
    	}
    }
    

    It's like it is not possible to assign a Connections to a Timer component.

    Can someone explain me if I'm right and why ?

    Thank's a lot ^^



  • @Moisi the answer is in the error message
    Cannot assign to non-existent default property



  • hi
    @Moisi said in Is it possible to make a Connections in a QmlTimer component ?:

    Cannot assign to non-existent default property

    Don't define the Connections inside the Timer.

    Timer {
     d: timerId
     property int nbr: 13
    	}
    
    Connections {
     target: itemId
     onMySignal: timerId.nbr = 42;
    	}
    

    In this context you don't even need Connections

    Item {
     id: itemId
     signal mySignal()
     onMySignal : timerId.nbr = 42;
    }
    


  • Hi,

    Thank you for your answer.

    Yes, this is a solution. ^^

    But I'm still curious about the reason why I can not define the Connections inside the Timer.



  • @Moisi the answer is in the error message
    Cannot assign to non-existent default property



  • Oh, yes ! You're right ! Thank you ! ^^


Log in to reply