PDA

View Full Version : Getting QLabel to work with WinAPI GetWindowText?



m.parker
22nd December 2006, 01:12
I'm writing some test scripts for a multi-component system. One of the components is a status monitor written with Qt4. Using WinAPI calls, I can get hwnds for all the widgets in the app window, but don't know how to get the text inside the controls. The standard GetWindowText winapi call returns nothing for most of the widgets.

I would like to either

A) Get the various text widgets to respond to the GetWindowText WinAPI function

or

B) Get the widget's text contents through some other method that doesn't involve code changes to the Qt app. This method would be preferable since I'm not the coder for the component in question. Is there a way to get from the hwnd to the QLabel text using only WinAPI calls or perhaps routines from a Qt dll?

Thanks,

Michael

Brandybuck
22nd December 2006, 03:29
All widgets live in a parent/child hiearchy. If you have access to the Qt based component, you can get access to all of its children. The best way to access the label depends on how much information you know about it. If you know its object name, then QObject::findChild() is handy. If you know it's position, you can use QWidget::childAt(QPoint*). As a last resort, you can iterate through the hiearchy looking for the widget with the given HWND.

This, of course, assumes access to the parent component's methods. If you don't have this level of access, you're probably out of luck.

m.parker
22nd December 2006, 20:46
The test script is a separate process. In order to have access to the QWidget-specific calls, I would need a way to convert the hwnd obtained through the WinAPI into a QWidget object. If there is a way to do this, I would be ecstatic.

From outside the running Qt app, I get the hwnd to the app through the EnumWindows WinAPI call, then feed this into EnumChildWindows to iterate through all the QWidgets in the app.

With the control's hwnd in hand, I can get things like the Windows class name (QWidget), as well as simulate user actions by sending windows messages like WM_LBUTTONDOWN / WM_LBUTTONUP.

What I'm having trouble with is getting data out of the control. Froglogic has a testing program called Squish with a spy feature than can attach to a running app and explore the entire control tree / properties etc. All I really need is the control text.

Any help appreciated,

Michael

wysota
22nd December 2006, 21:22
Squish uses Qt API to do the job, the only platform specific thing is the attachment to the AUT itself, at least I think so :)