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

How to block signal in QML



  • Hi. How can I block/unblock specific signal in QML? For example "onContentYChanged".



  • @PawlosCK
    It's a bit unclear to me what you want to do. If you are programatically changing contentY and you don't want a "feedback"-like reaction of your code you could define a

    property bool busy: false
    

    which you set to true while doing your thing. The method "onContentYChanged" can then be made conditional:

    onContentYChanged: {
        if (!busy) {
        }
    }
    

    HTH
    KR
    Sebastian



  • Hi. I did it and it didn't work. I mean, slot should not be executed, but I saw logs from this slot.
    I wanted to block signal at startup (and later in some cases), because function setValues adds new items at startup and this signal was invoked.
    I tried to disconnect signal from object using something like this (it's not from my code), but it didn't work too.

     mouse.clicked.disconnect(say);
     mouse.clicked.connect( function(){ console.log("22222")  });
    

    Next, I tried to use "Connections"

            Connections
            {
                id: connection_signal_move_items
                target: listviewID
                function onCurrentItemChanged() { listviewID.moveItemsTouchAndMouse() }
                enabled: false
            }
    		
    		connection_signal_move_items.enabled = false
    		connection_signal_move_items.enabled = true
    

    and it didn't work too, so I didn't know where is problem. I thought, that I did something wrong and I started this thread.

    Currently, I started use other signal and currently looks well. I have to test it more.


Log in to reply