Results 1 to 7 of 7

Thread: Hooking Qt Signals/Slots

  1. #1
    Join Date
    Jul 2010
    Posts
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Hooking Qt Signals/Slots

    I need to write an app that somehow can 'hook' onto another Qt app to display all the Signals/Slots being emitted/exec'd. Similar to a Spy++ app with windows. It's not possible to map the Signals/Slots inside the app because the Qt app's I'm trying to 'hook' are already older apps we don't want to waste time rewriting/modifying.

    I've written Qt code that can hook Qt apps using SetWindowsHookEx() but it cannot display the emitted Signals.

    Is there any methods for hooking an existing Qt app to view the Signals being emitted?

    Thanks,
    Mike H
    mheese@efji.com

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hooking Qt Signals/Slots

    Not without modifying the source code. If you don't mind a recompile, then take a look at QSignalSpy, but one process can not monitor another processes signals, and those signals are are processed internally.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Hooking Qt Signals/Slots

    Is this something you want?
    http://sourceforge.net/projects/conanforqt/

  4. #4
    Join Date
    Jul 2010
    Posts
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Hooking Qt Signals/Slots

    Thanks for the response!

    What about through QProcess or another Qt Class? I could work with the connect() function but would need to find a way to get a pointer to the running app?

    Is it possible to get some kind of QObject (or other) pointer to a running Qt app, say, if it was launched using QProcess??

    for example, are there any methods through QProcess (or other class) that would do:

    CMyMainWindowClass::CMyMainWindowClass(){
    . . .

    m_myProcess = new QProcess(this);
    m_myProcess->start("myoldQtapp.exe", arguments);

    QObject *obj = m_myProcess->GetQtObjectPointerToApp(); //how could I get the running app's QObject or QMainWindow pointer for connecting Slots to??

    connect(obj, SIGNAL(oldappsignal()), this, SLOT(OnOldAppSignal()));
    }

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Hooking Qt Signals/Slots

    If you dynamically link your program, you can easilly inject another library that overrides some functions and thus you gain complete access to your program from an "external" source.

    Edit: how this is done on Windows, I don't know. On linux you use LD_PRELOAD to load your custom library first.

    And, the work this takes, I guess you can also put it directly in your program without resulting to hacks.
    Last edited by tbscope; 4th October 2010 at 18:47.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hooking Qt Signals/Slots

    Quote Originally Posted by mlheese View Post
    Thanks for the response! What about through QProcess or another Qt Class?
    Each process uses a different memory space, so one process can not access another processes memory directly. They have to access it through API calls such as ReadProcessMemory and WriteProcessMemory, which would be far too slow for your requirement.

    You could inject a DLL into the process at run time, or replace a DLL if your apps are dynamically linked (as suggested by tbscope) but the time taken to do that would be more than it would take to just recompile the program with modifications, and recompiling would be far more reliable.

  7. #7
    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: Hooking Qt Signals/Slots

    Quote Originally Posted by tbscope View Post
    If you dynamically link your program, you can easilly inject another library that overrides some functions and thus you gain complete access to your program from an "external" source.

    Edit: how this is done on Windows, I don't know. On linux you use LD_PRELOAD to load your custom library first.
    You can always craft a custom QtCore library which will dump something to the console every time QObject::connect() and QMetaObject::metacall() are called. You can even make it read some configuration from an external source to dump only those things you are interested in.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. about signals and slots
    By Sandip in forum Qt Programming
    Replies: 9
    Last Post: 15th July 2008, 16:02
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. regarding signals/slots
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2007, 09:32
  4. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 08:11
  5. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12

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.