Project

General

Profile

How to disconnect from a Signal after it was fired once

Added by Christian Meyer 3 days ago

I am trying to build a CMS with unlimited nested Menu items.

That in itself works and is not the issue.

I want to create and show the menu when the mouse is hovered on an item with a submenu.
that works by connecting to mouseWentOver() signal of the item.

But that fires all the time when the mouse moves over the item and is not needed anymore, as the menu is already created, and the showing and positioning are done via css.
I added a connection object to the item that stores the connection on the signal.
within a lambda Slot, I disconnect() the connection, but the event is still fired.
I tried doJavaScript(this->jsRef() + ".onmouseover=null") and that stops the firing and the server roundtrip, but fails inside the lambda with a segfault.

connecting to a handleHover() Function with the required functionality works as expected.

Does it make sense to add a connectOnce() function to the SignalBase class?

just like a SingleShot Timer?

why does disconnect() not stop the server roundtrips?

Cheers
Christian


Replies (1)

RE: How to disconnect from a Signal after it was fired once - Added by Matthias Van Ceulebroeck 2 days ago

Hello Christian,

I believe you are working with the right idea here. I would also thinh, about keeping track of the connection object, and disconnect() it. That should work.
Now, where I think it goes wrong: you notify the server the signal ought to no longer be listened, to. But the client side is still firing them. Unless the client is updated, it will keep doing so.
I suspect you will have to WApplication::enableUpdates(), and push the change out.


Now, I do think that what you did, namely disconnecting the signal ought to remove the exposed signal from the application. So that at least until the client is updated, the application will no longer consider the input from the signal valid, and ignore it.
I will investigate some more in a couple days.

Best,
Matthias

    (1-1/1)