Hi,
I'm getting this really strange situation, on multiple (unix-based) platforms, whereby a signal that I emit once results in multiple calls to the same slot. The slot does time-critical inter-process communication via socket connections, so this is pretty debilitating. Here's the signal:
class MyClass
{
Q_OBJECT
...
signals:
void WriteToProc(const QByteArray& qb, int* num_bytes = NULL);
};
MyClass::SendData(...)
{
... //Fill up qb;
qDebug() << "Emitting signal";
emit WriteToProc(qb);
}
class MyClass
{
Q_OBJECT
...
signals:
void WriteToProc(const QByteArray& qb, int* num_bytes = NULL);
};
MyClass::SendData(...)
{
QByteArray qb;
... //Fill up qb;
qDebug() << "Emitting signal";
emit WriteToProc(qb);
}
To copy to clipboard, switch view to plain text mode
Here's the slot (has the same name):
class MyWorkerThread
: public QThread{
Q_OBJECT
...
public slots:
void WriteToProc(const QByteArray& qb, int* num_bytes);
private:
QLocalSocket* socket_out;
};
void MyWorkerThread::WriteToProc(const QByteArray& qb, int* num_bytes)
{
if (num_bytes==NULL) socket_out->write(qb);
else *num_bytes = socket_out->write(qb);
qDebug() << "MyWorkerThread::WriteToProc";
}
class MyWorkerThread : public QThread
{
Q_OBJECT
...
public slots:
void WriteToProc(const QByteArray& qb, int* num_bytes);
private:
QLocalSocket* socket_out;
};
void MyWorkerThread::WriteToProc(const QByteArray& qb, int* num_bytes)
{
if (num_bytes==NULL) socket_out->write(qb);
else *num_bytes = socket_out->write(qb);
qDebug() << "MyWorkerThread::WriteToProc";
}
To copy to clipboard, switch view to plain text mode
There's some stuff in there that's not directly relevant to the point that I include for completeness. SendData() and WriteToProc are in different threads, and the connection type is default (Qt::QueuedConnection). Anyway, the output is e.g.
Emitting signal
MyWorkerThread::WriteToProc
MyWorkerThread::WriteToProc
MyWorkerThread::WriteToProc
Moreover, looking at the output at the other end, I can see that the QByteArray is getting sent 3 (in this case; it can vary) times. I've verified that only SendData() is calling WriteToProc at that point. It's so weird--what could be going on?
Best,
Matt
Bookmarks