Results 1 to 7 of 7

Thread: Cross thread signals (QueuedConnection). Miss SOME signals!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Cross thread signals (QueuedConnection). Miss SOME signals!

    Hi all.

    I have weired problem with signals sending between threads.

    1) I have a thread. In the run() function I create a signals reciever object and connect signals to it:
    Qt Code:
    1. void LogServiceThread::run()
    2. {
    3. // Create worker.
    4. try
    5. {
    6. m_impl->m_worker.reset(new LogWorker(m_impl->m_fileName));
    7. }
    8. catch (...)
    9. {
    10. // Ignore all exceptions. If something gone wrong with worker - continue work silently.
    11. }
    12. // Connect signals to worker.
    13. if (!m_impl->m_worker.isNull())
    14. {
    15. connect(this, SIGNAL(writeAsynchSignal(QString)), m_impl->m_worker.data(), SLOT(writeMessage(QString)), Qt::QueuedConnection);
    16. }
    17. // Run event loop.
    18. exec();
    19. }
    To copy to clipboard, switch view to plain text mode 
    2) Now I try to send som signals to it by main thread
    Qt Code:
    1. void LogServiceThread::writeAsynch(const QString & string)
    2. {
    3. emit writeAsynchSignal(string);
    4. }
    To copy to clipboard, switch view to plain text mode 

    So basically, this is an asynchronous thread safe logger. And I got weired problem: sometimes SOME log messages are missing. Some signals are emited but never come to slot! Sometimes I got all messages during run, some times only few.

    What I am missing?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Cross thread signals (QueuedConnection). Miss SOME signals!

    What happens if you change the signature of writeAsynch() to:
    Qt Code:
    1. void writeAsynch(QString string)
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Cross thread signals (QueuedConnection). Miss SOME signals!

    @up: this doesn't change anything.

    @topic: not enough information! I have no idea what you should say more! First check debug logs, maybe Qt warns about some run time problems.
    Secondly describe what you are trying to do? Maybe you can do it better way?

Similar Threads

  1. Replies: 5
    Last Post: 22nd February 2011, 21:21
  2. Replies: 1
    Last Post: 24th October 2010, 11:09
  3. Replies: 8
    Last Post: 1st June 2009, 19:59
  4. Problem using signals and thread
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2008, 13:57
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18

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.