Hi,
I am trying to figure out how to emit a signal from one my threads to another thread, both non-gui threads. I see in the Qt documentation it is possible, I just cannot figure it out.
Seems like I need something like, I am just not sure in the NetReceive class.
connect(this, SIGNAL(checkNetQueue()), <ptr to other thread>, SLOT(processNetQueue()), Qt::QueuedConnection);
Here is a little background on how my classes are setup:
NetworkThread is a abstract parent class and I have two children from that thread, NetThread and NetReceiveThread. I want NetReceiveThread to emit a signal to the NetThread. If I emit the signal from NetThread itself, the slot executes and works fine.
The threads are created in my Main GUI window as class variables, like NetThread t1, NetReceiveThread t2. And then start() is called on each of them inside the MainWin constructor.
Any ideas you can come up? I appreciate the help.
Thanks so much.
RishiD
---------------------------------------------------------------------
Here are some small snippets of my three thread headers.
NetworkThread.h
class NetworkThread
: public QThread{
Q_OBJECT
public:
NetworkThread() { };
signals:
void checkNetQueue();
};
class NetworkThread : public QThread
{
Q_OBJECT
public:
NetworkThread() { };
signals:
void checkNetQueue();
};
To copy to clipboard, switch view to plain text mode
NetThread.h
class NetThread : public NetworkThread
{
Q_OBJECT
public:
NetThread();
protected:
void run()
{
// emitting checkNetQueue() works fine, if the emit is run inside the NetThread
connect(this, SIGNAL(checkNetQueue()), this, SLOT(processNetQueue()));
exec();
}
private slots:
void processNetQueue();
}
class NetThread : public NetworkThread
{
Q_OBJECT
public:
NetThread();
protected:
void run()
{
// emitting checkNetQueue() works fine, if the emit is run inside the NetThread
connect(this, SIGNAL(checkNetQueue()), this, SLOT(processNetQueue()));
exec();
}
private slots:
void processNetQueue();
}
To copy to clipboard, switch view to plain text mode
NetReceiveThread.h
class NetReceiveThread : public NetworkThread
{
Q_OBJECT
public:
NetReceiveThread(){}
protected:
void run()
{
// need to change the second this, to a pointer to NetThread
// connect(this, SIGNAL(checkNetQueue()), this, SLOT(processNetQueue()),
// Qt::QueuedConnection);
receiveLoop() // <--- calls emit checkNetQueue();
}
};
class NetReceiveThread : public NetworkThread
{
Q_OBJECT
public:
NetReceiveThread(){}
protected:
void run()
{
// need to change the second this, to a pointer to NetThread
// connect(this, SIGNAL(checkNetQueue()), this, SLOT(processNetQueue()),
// Qt::QueuedConnection);
receiveLoop() // <--- calls emit checkNetQueue();
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks