How to read QTextEdit content from another application?

1.6k views Asked by At

I'm currently trying to make a debugging tool which will sit on top of a proprietary application (which interfaces over BLE with hardware).

Inside of this application (written in QT) there is a text box which has the stream of logging information coming from the hardware, and I want to make an application which will monitor that text box and process the data being logged.

I cracked open Spy++ and found the handles of the window I needed, however, it only displayed as "QWidget" and WM_GETTEXT wasn't pulling any data out. These two links also mention that QT widgets can't be read by the standard Win32 API (which feels strange to me, as I was sure everything needed to pass through the Windows GUI layer): https://forum.qt.io/topic/36867/accessing-qtextedit-from-another-program/9 https://forum.qt.io/topic/19256/how-get-handle-of-qwidget-child-with-vb-net/9

I'm open to any and all options! I'm language-agnostic on this one. How can I read out the QTextEdit logging data?

2

There are 2 answers

1
IInspectable On BEST ANSWER

Qt's widgets support Assistive Technology (AT) out of the box. On Windows, Qt's Accessibility is available through MSAA and IAccessible2. Either one is capable of inspecting widget trees, and delivering a widget's properties across process boundaries.

Either interface is officially supported by Qt.

13
ixSci On

You can't read the content of a QTextEdit because it is an alien widget. You can read more in QWidget documentation:

Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing system. They do not have a native window handle associated with them. This feature significantly speeds up widget painting, resizing, and removes flicker.

Should you require the old behavior with native windows, you can choose one of the following options:

  1. Use the QT_USE_NATIVE_WINDOWS=1 in your environment.

  2. Set the Qt::AA_NativeWindows attribute on your application. All widgets will be native widgets.

  3. Set the Qt::WA_NativeWindow attribute on widgets: The widget itself and all of its ancestors will become native (unless Qt::WA_DontCreateNativeAncestors is set).

  4. Call QWidget::winId to enforce a native window (this implies 3).

  5. Set the Qt::WA_PaintOnScreen attribute to enforce a native window (this implies 3).


Also there is an introspection tool for Qt which might be of use for you: GammaRay. Personaly I didn't use it - only read a small overview but it looks promising.