0

I know very similar questions have been asked before, but I am unable to find an answer for my specific problem. I have a main (GUI) thread which upon button press initializes a worker thread to perform some analysis. I am using signals and slots to communicate between my worker thread and my GUI thread (i.e. when the thread starts and when it finishes), but I need to go deeper than that. My worker thread actually calls another class in a separate implementation file which then iterates through a series of calculations which are sent to std::cout for each iteration (as the code used to be a console application for which I am now writing a GUI). I am trying to feed those outputs for each iteration back into my GUI thread so that my text browser is updated in real time as my code iterates. The problem is, when I emit a signal from the class my worker thread calls, it is not picked up by the GUI thread. I do not get any errors. Does anyone have any suggestions on how to transmit a signal to the GUI from a class that my worker thread is calling? I can post code as required, but I'm not sure what would be most helpful to see and my code is quite extensive (it's an aircraft performance application). Any help would be greatly appreciated. Thank you kindly!

GTSeth
  • 1
  • 4
  • From what you are saying, this seems impossible, so to debug this, maybe you could check the thread association of each object, maybe some object is not on the thread you expect it to be. Then check the connections, and whether the cross-thread connections are made correctly. – Bgie Apr 15 '14 at 14:32

1 Answers1

0

1) Make sure the connect() call for connecting you signal returns true. If it does not, qdebug output usually tells you what is wrong

2) You should use the QueuedConnection type (the default (Auto) should work also)

tpatja
  • 690
  • 4
  • 11
  • I'm not entirely sure how to check if my connect() returns true. I tried: 'bool ok = connect(deck, SIGNAL(prop()), this, SLOT(converter())); Q_ASSERT(ok);' but there's no output – GTSeth Apr 15 '14 at 14:48
  • That should do it. If the Q_ASSERT fails, you'll a qFatal() message. The output will also have a reason why it failed. Be sure to check the debug output. – tpatja Apr 15 '14 at 14:52
  • be also sure to compile and run in debug mode – ratchet freak Apr 15 '14 at 15:01
  • @tpatja I suppose I should mention this project has been built within NetBeans 7.3. I built and compiled in debug mode but got no messages from Q_ASSERT. – GTSeth Apr 15 '14 at 15:10
  • I havent used Netbeans with QT, but imagine there must be a way to get qDebug output with it. You can also put a breakpoint and check the connect() return value in the debugger. – tpatja Apr 15 '14 at 15:15
  • There is no reason to use an explicit queued connection here. Qt will do the right thing by default. – Kuba hasn't forgotten Monica Apr 15 '14 at 17:34