Wireshark-dev: [Wireshark-dev] Slot on main thread not called when signal is emitted from anoth
I am trying to write a plugin for Wireshark that will run a TCP server on a service thread. The TCP server will receive a new frame number from another application and then use the Plugin IF function plugin_if_goto_frame to cause Wireshark
to jump to the new frame number. I have found through various experiments that plugin_if_goto_frame must run on the main thread. I'm writing the plugin in Qt and C++, exposing the callbacks using extern "C" declarations. The callbacks are being called correctly
and that all looks fine. I’m using a Qt cross-thread (QueuedConnection) signal and slot to communicate between my service thread and the main thread. The problem I am having is that although the service thread emits the signal (well it executes the instruction)
the slot in the main thread doesn’t get called. I’ve removed all of the TCP server code to simplify things. The relevant bits of the code looks like this: syncro.h #ifndef SYNCRO_H #define SYNCRO_H #include <QtCore> #include "mythread.h" class Syncro : public QObject { Q_OBJECT public: void Initialise(MyThread *); public slots: void jumpToFrame(int); }; #endif // SYNCRO_H syncro.cpp #include <plugin_if.h> #include "syncro.h" #include <QtCore> #include <QDebug> void Syncro::Initialise(MyThread *serviceThread) { // connect(serviceThread, SIGNAL(syncroGoFrame(int)), this, SLOT(jumpToFrame(int)), Qt::DirectConnection); connect(serviceThread, SIGNAL(syncroGoFrame(int)), this, SLOT(jumpToFrame(int)), Qt::QueuedConnection); } void Syncro::jumpToFrame(int new_frame) { plugin_if_goto_frame(new_frame); return; } mythread.h #ifndef MYTHREAD_H #define MYTHREAD_H #include <QtCore> class MyThread : public QThread { Q_OBJECT public: MyThread(); void run(); signals: void syncroGoFrame(int); }; #endif // MYTHREAD_H mythread.cpp #include "mythread.h" #include <QtCore> #include <QDebug> MyThread::MyThread() { } void MyThread::run() { while (true) { qDebug() << "Running"; sleep(3); qDebug() << "Still Running"; emit syncroGoFrame(22); } } packet-syncro.cpp static int proto_syncro = -1; static MyThread *serviceThread; static Syncro *mainObject; void proto_register_syncro(void) { module_t *syncro_module; proto_syncro = proto_register_protocol("Syncro Service", "Syncro", "syncro"); syncro_module = prefs_register_protocol(proto_syncro, proto_reg_handoff_syncro); if (!serviceThread) { serviceThread = new MyThread; mainObject = new Syncro; mainObject->Initialise(serviceThread); serviceThread->start(); } return; } When I run the code the extra thread starts OK and it starts to cycle around the loop with the 3 second sleep. However, the connected slot function Syncro::jumpToFrame(int new_frame) does not get called. If I change the connect from QueuedConnection
to DirectConnection the slot function gets called but, as expected, in the context of my serviceThread. I need the slot function to run on the main thread. I guess it is because my jumpToFrame slot function is not on the main thread event loop, but I don’t understand how to get it on the loop. Any advice would be much appreciated. Thanks and regards…Paul ______________________________________________________________________ This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Advance Seven Ltd. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. Advance Seven Ltd. Registered in England & Wales numbered 2373877 at Endeavour House, Coopers End Lane, Stansted, Essex CM24 1SJ ______________________________________________________________________ This email has been scanned by the Symantec Email Security.cloud service. For more information please visit http://www.symanteccloud.com ______________________________________________________________________ |
- Follow-Ups:
- Prev by Date: Re: [Wireshark-dev] Chained CAN dissecector: Can not get reference for CAN dissector
- Next by Date: Re: [Wireshark-dev] Slot on main thread not called when signal is emitted from another thread
- Previous by thread: Re: [Wireshark-dev] Chained CAN dissecector: Can not get reference for CAN dissector
- Next by thread: Re: [Wireshark-dev] Slot on main thread not called when signal is emitted from another thread
- Index(es):