Results 1 to 4 of 4

Thread: Getting QLabel to work with WinAPI GetWindowText?

  1. #1
    Join Date
    Dec 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Getting QLabel to work with WinAPI GetWindowText?

    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

  2. #2
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Getting QLabel to work with WinAPI GetWindowText?

    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.

  3. #3
    Join Date
    Dec 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Getting QLabel to work with WinAPI GetWindowText?

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Getting QLabel to work with WinAPI GetWindowText?

    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

Similar Threads

  1. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 03:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.