Why does a Qt application only create window handles if Spy++ is running?

Viewed 172

I'm trying to automate an old Qt 4 application (for which I don't have the source code). If I run the application before running Spy++, Qt does not create window handles for child widgets. If I run the application after Spy++, window handles are created for child widgets like buttons and I can find them with FindWindow.

What is Spy++ doing to make Qt create child window handles and how can I do that in my own program?

1 Answers

(Update: just saw that @G.M. provides a link to documentation that also answers this.)

After some searching, I think I know why this happens.

It happens, because you do it ;-)

Spy++ apparently sends WM_GETOBJECT window message to the application, just like Microsoft Active Accessiblity would.

Qt, is smart enough to intercept those messages and adjust accordingly, i.e. not using alien widgets, but native ones - because the lightweight/alien ones are not visible to the Windows accessibility machinery. (Apparently, this was a wrong assumption as pointed out by @IInspectable's comment; thanks)

In other words you cannot use Spy++ to look at non-native widgets with Qt. The logic works both ways: you cannot do it because Spy++ causes Qt to use native widgets; even if it did not (Qt had no WM_GETOBJECT-handling), you wouldn't see any childwindows for Qt widgets, because there wouldn't be any (native ones).

Related