[Qt-interest] How do QApplication relates to QWidget

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Jul 28 11:14:22 CEST 2010


wei wrote on Wednesday, July 28, 2010 9:27 AM:

> ...
> So how can "app" know it has a widget named "win"? If "app" don't
> know the fact, how can it process and dispatch messages related to
> win?  

Very simply put (because I don't know the details either):

- Instantiating a QApplication *initialises* internal resources such as the "connection" to the underlying painting system, (on Windows that might be the GDI API, on Mac either Cocoa or Carbon etc.), registers with the native message system ("Windows Close" messages and the like)...

- Instantiating a QWidget then *uses* those resources

By using those resources the corresponding QWidget "registers" with the Qt event queue, and the "Qt core" then also "knows" that this widget exists and can inform it correspondingly (e.g. when the mouse button is clicked).

I might have over-simplified it, but basically that is how I think it works. That is also the reason why you need to *first* instantiate a QApplication before you use any QWidget or QPainter (or other classes which depend on resources that are initialised by QApplication).

Other classes however such as QString can work on their own, that is they don't need "native" resources.

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list