2

I've injected into a proprietary Qt (4.5.2) application, added my own compatible build of QtScript, and have managed to get access to all the signals I need. However, when connecting to them (via QtScript) my functions are never called.

I've come up with a few theories for why this is and I've tested everything I can think of, but I've hit a bit of a wall. Note, I've never had any connection exceptions whatsoever. Here are my current theories:

  • The signals I'm connecting to are already connected to other slots, and that's somehow blocking it (but as far as I know, all Qt signals fire to all slots with no extra work, and can't be restricted in this way)
  • The signals are rejecting my connection, or disconnecting me after connection (but I see no facility for this)
  • My connection is happening from another thread, and this is somehow causing it not to connect properly

Are any of these theories plausible? If not, what have I missed?

Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114
  • 2
    First theory is definitely wrong. Qt signals calls all slots connected to them. – VestniK May 03 '10 at 14:37
  • Is it possible that the signal is not emitted? – Lohrun May 03 '10 at 15:29
  • Nope, if I block the signal(s) from hitting the object I know they're connected to (I hooked QObject::connect and worked backwards from that to get the object containing the signals I'm attaching to) the related events don't occur. – Serafina Brocious May 03 '10 at 15:35

2 Answers2

3

After a whole lot of digging around internals and asking a lot of questions (here and in #qt on Freenode, namely), I managed to get it to work. The problem was that my injected code ran in a native thread without an event pump. Instantiating QEventLoop and calling processEvents() at regular intervals solved this.

Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114
0

This question is really old and already answered but for those that come here looking for help and for who the above is not a good solution, you might want to consider setting the Qt::ConnectionType in the connect statement to Qt::DirectConnection like so:

QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
                 label,  SLOT(setNum(int)),
                 Qt::DirectConnection);

Which should solve the same problem in a different way.

svenstaro
  • 1,783
  • 2
  • 21
  • 31