Is UnBind() method safe?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Part Of The Furniture
Part Of The Furniture
Posts: 3049
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Is UnBind() method safe?

Post by ONEEYEMAN » Wed Aug 08, 2018 2:33 pm

What I am trying to do is the following:

1. On some condition in the program I'm doing Bind(). If condition is false Bind() is not executed. The event I'm binding is wxFileSystemWatcher one.
2. Inside some other event handler I want to execute UnBind() method.

2 questions:
1. If the Bind() was not executed, is it safe to un-bind the event?
2. If the answer to 1 is no - what is the best way to achieve it? I don't think there is an IsEventBound() method...

Thank you.

Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 656
Joined: Mon Apr 30, 2012 11:07 pm

Re: Is UnBind() method safe?

Post by Manolo » Wed Aug 08, 2018 4:32 pm

The docs for bool wxEvtHandler::Unbind say:
Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
The code at common/event.cpp for bool wxEvtHandler::DoUnbind shows that in any other case different from the above the function returns false. IOW, no functor/handler in the dynamic table, then return false.

A good advise is found at ... abled.html:
...if you only bind and unbind same event handler inside same binary, you should be fine
Summary: Is ir safe?, I'd say "yes".

Post Reply