Wireshark-dev: Re: [Wireshark-dev] Slot on main thread not called when signal is emitted from a

From: Paul Offord <Paul.Offord@xxxxxxxxxxxx>
Date: Wed, 16 Dec 2015 14:45:42 +0000
Well that was frustrating.  The answer to my problem is that I had mixed release and debug objects.  I have been adding Qt Libraries to the Linker Input list like this:

\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Core.lib
\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Widgets.lib
\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Gui.lib
\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Network.lib

I have now changed the include list to:

\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Cored.lib
\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Widgetsd.lib
\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Guid.lib
\Qt\Qt5.5.1\5.5\msvc2013_64\lib\Qt5Networkd.lib

Now QApplication::instance() returns the pointer and my slot is now working.

Thanks Gerald for your advice, which in a roundabout way led me to the solution.

Best regards...Paul

-----Original Message-----
From: Paul Offord 
Sent: 16 December 2015 11:45
To: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
Subject: RE: [Wireshark-dev] Slot on main thread not called when signal is emitted from another thread

Sorry - ignore that stupid last question about class name vs. instance.  I should have researched the function a  little so I understood what you are driving at.

I did a bit of research and it seems that although QApplication::instance() doesn't exist but QCoreApplication::instance() does.  I've tried it as a direct replacement and that doesn't work but I've seen a lot of chit chat on the Qt forum about recasting the returned pointer so I'll look further.

Best regards...Paul

-----Original Message-----
From: wireshark-dev-bounces@xxxxxxxxxxxxx [mailto:wireshark-dev-bounces@xxxxxxxxxxxxx] On Behalf Of Paul Offord
Sent: 16 December 2015 11:30
To: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
Subject: Re: [Wireshark-dev] Slot on main thread not called when signal is emitted from another thread

Do you mean like this?

syncro.h

#ifndef SYNCRO_H
#define SYNCRO_H
#include <QtCore>

#include "mythread.h"

class Syncro : public QObject
{
	Q_OBJECT

public:
	Syncro();
	void Initialise(MyThread *);

public slots:
	void jumpToFrame(int);
};

#endif // SYNCRO_H


Syncro.cpp

.
.
Syncro::Syncro()
{
	setParent(QApplication::instance());
}
.
.

The setParent(QApplication::instance()) shows as an error in VS - incomplete type is not allowed.  Don't I have to specify the QApplication instance rather than the class name?

Cheers...Paul

-----Original Message-----
From: wireshark-dev-bounces@xxxxxxxxxxxxx [mailto:wireshark-dev-bounces@xxxxxxxxxxxxx] On Behalf Of Gerald Combs
Sent: 15 December 2015 21:19
To: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
Subject: Re: [Wireshark-dev] Slot on main thread not called when signal is emitted from another thread

On 12/15/15 8:15 AM, Paul Offord wrote:

> 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.

Can you try adding a constructor to Syncro, and add either

  moveToThread(QApplication::instance()->thread());

or

  setParent(QApplication::instance());

to it? I'm not sure if QObjects have a valid thread affinity by default.
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe

______________________________________________________________________

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 ______________________________________________________________________
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe

______________________________________________________________________

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
______________________________________________________________________