Results 1 to 20 of 23

Thread: Qt bug? Signal emitted once, slot called multiple times

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt bug? Signal emitted once, slot called multiple times

    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:

    Qt Code:
    1. class MyClass
    2. {
    3. Q_OBJECT
    4. ...
    5. signals:
    6. void WriteToProc(const QByteArray& qb, int* num_bytes = NULL);
    7. };
    8.  
    9. MyClass::SendData(...)
    10. {
    11. ... //Fill up qb;
    12. qDebug() << "Emitting signal";
    13. emit WriteToProc(qb);
    14. }
    To copy to clipboard, switch view to plain text mode 

    Here's the slot (has the same name):

    Qt Code:
    1. class MyWorkerThread : public QThread
    2. {
    3. Q_OBJECT
    4. ...
    5. public slots:
    6. void WriteToProc(const QByteArray& qb, int* num_bytes);
    7. private:
    8. QLocalSocket* socket_out;
    9. };
    10.  
    11. void MyWorkerThread::WriteToProc(const QByteArray& qb, int* num_bytes)
    12. {
    13. if (num_bytes==NULL) socket_out->write(qb);
    14. else *num_bytes = socket_out->write(qb);
    15. qDebug() << "MyWorkerThread::WriteToProc";
    16. }
    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
    Last edited by MattPhillips; 28th October 2010 at 08:00.

Similar Threads

  1. [SOLVED] Two signals emitted, only one slot called!
    By codeverse in forum Qt Programming
    Replies: 0
    Last Post: 11th August 2010, 15:46
  2. Replies: 1
    Last Post: 7th December 2009, 18:49
  3. filterAcceptRows() is being called many times for same souceRow.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2009, 03:49
  4. Replies: 0
    Last Post: 17th May 2008, 18:06
  5. Replies: 2
    Last Post: 16th August 2007, 00:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.