Project

General

Profile

Cancel / break a signal.

Added by prest1ge c0ding almost 9 years ago

Hello community.

Is it possible to catch a signal to accept / or cancel it?

So i have a WTabWidget which has some closable tabs.

In some tabs i need to handle some other operations before this tab gets closed.

I know there are the signal WMenu::itemClosed()

...but this does not really help because this signal are much to late.

At this moment the tab IS already closed.

But i need to block / break this close event.

Pseudo-code:

WMenuItem -> willClose().connect (...)
    if (unsaved-data)
        theMenuItem -> dontClose();

Replies (4)

RE: Cancel / break a signal. - Added by Stefan Arndt almost 9 years ago

Hi,

in general you can get and work with a connection when you created it of your own. That's what the return value of a call to "connect()" is for (see Wt::Signals::Connection).

But because your are working with the Wt widgets, you have no way of getting theses connections (at least none I know about).

Just my ideas to solve your problem:

  • Your tabs just display your data. Move any data you might need later on to some kind of Data Center/Manager/Handler that is common to all tabs. Then, when closing a tab, you can process your unsaved-data and get it from the Data Center and not from the tab that has already been closed. Try to avoid that the tabs know about each other, they should just know about the data.
  • If your data are abstracted properly there should be no need of a willClose-event. The destructor of the resource should handle anything (and might inform other resources that he is going to die now). In the worst case the destructor of the tab will take some time.

Ask again, if that does not solve your problem :)

RE: Cancel / break a signal. - Added by prest1ge c0ding almost 9 years ago

Hey Stefan, thanks for your suggestion.

My idea was to subclass WMenuItem where i overload the clicked signal from the 'closeicon'.

If my data is saved i can emit the original WMenuItem close signal, if not, ...

i can doSomething();

But my Problem is, i can not figure out how to subclass a WMenuItem.

RE: Cancel / break a signal. - Added by Koen Deforche almost 9 years ago

Just specialize WMenuItem and use WMenu::addItem(WMenuItem *item) instead of the other variants?

RE: Cancel / break a signal. - Added by Christian Altmeier over 7 years ago

prest1ge c0ding wrote:

But i need to block / break this close event.

Pseudo-code:

[...]

Same issue here. We have to request another component of our software which allows us to finally close a tab or not.

I haven't any ideas how to solve this issue with the information from this thread.

Can you provide me some detailed advice how I implement a "before close" handling? What steps are to do to solve this?

Thanks in advance!

    (1-4/4)