+-----------------------------------------------------------------------------------------+
| Application |
| |
| +---------------+ +-----------------------------------------+ |
| +---------------+| | Application code, contains objects. | |
| +---------------+|| | | |
|
+---------------+||| | mainWindow
(a
QMainWindow) | |
| | Linked |||+ | | | |
| | |
+ |
+-- label
(a
QLabel) | |
| +---------------+ +-----------------------------------------+ |
| | |
| v |
| +-------------------------------------------------------------------------------------+ |
| | Your injected DLL | |
| | | |
| | +--------------------------+ | |
| | | inside DLL | | |
| | | | | |
| | | Contains signals and | | |
| | | slots | | |
| | +--------------------------+ | |
| | | | |
| | v | |
| | +-------------------------------------------------------------------------+ | |
| | | Create an object: | Do this from within a context | | |
| | | | where the application event | | |
| | | MyClass *myclass = new MyClass; | loop is running. | | |
| | +-------------------------------------------------------------------------+ | |
| | | | |
| | v | |
| | +------------------------------------------------+ | |
| | | Example: | | |
| | | Suppose you have installed an application | | |
| | | event filter. | | |
| | | | | |
| | | Also, suppose you intercept the mainWindow | | |
| | | show event. | | |
| | | | | |
| | | From this event, you have a pointer to | | |
| | | mainWindow, let's call it pMainWindow | | |
| | | | | |
| | | Then you can write: | | |
| | | | | |
| | | connect(pMainWindow->button, SIGNAL(...), | | |
| | | myclass, SLOT(...)); | | |
| | | | | |
| | | | | |
| | | In pseudocode: | | |
| | | ---------------------------------------------- | | |
| | | when application started | | |
| | | install eventfilter | | |
| | | | | |
| | | when eventfilter gets called | | |
| | | check the event and the target object | | |
| | | if event = show and object = mainWindow | | |
| | | Create a new MyClass object if none | | |
| | | already exists. | | |
| | | Connect signals and slots | | |
| | | | | |
| | +------------------------------------------------+ | |
| | | |
| +-------------------------------------------------------------------------------------+ |
| |
+-----------------------------------------------------------------------------------------+
Bookmarks