Project

General

Profile

Accessing WApplication from WContainerWidget

Added by Artur Adib about 15 years ago

Another quick question...

Since WContainerWidget classes don't inherit methods from WApplication, how can one access "WApplication::environment()" or "WApplication::doJavaScript()" from within such a widget class?

Wouldn't it be nice if WContainerWidget offered such a mechanism by construction?

My own hack is to pass my current WApplication object to the constructor of my WContainerWidget, which in turn stores that pointer to be used as necessary. But of course this solution is cumbersome if one needs to keep passing WApplication pointers down the inheritance chain...

Thanks!


Replies (1)

RE: Accessing WApplication from WContainerWidget - Added by Wim Dumon about 15 years ago

You can always use the global symbol 'wApp' (Short for Wt::WApplication::instance()) to access the current WApplication. The environment is thus wApp->environment(). This uses thread-local storage to fetch the WApplication pointer for the active application. Side note: if you create threads yourself (like worker threads) that use Wt objects, you may need to call Wt::WApplication::attachThread() manually in order to set this thread-local storage correctly.

    (1-1/1)