Results 1 to 8 of 8

Thread: BlockingQueuedConnection hang

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default BlockingQueuedConnection hang

    Hi,

    My application have 2 threads, one to grab images from a camera and the second to perform some process to the images.

    I'm trying to use "BlockingQueuedConnection" to emit image pointers(from the process thread)that are displayed into the Main Thread.

    It works perfectly until I stop the threads, where the application hangs.
    Òscar Llarch i Galán

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: BlockingQueuedConnection hang

    Why a BlockingQueuedConnection?

    Where are you stopping the threads?

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BlockingQueuedConnection hang

    Hi,

    I'm trying to use BloquingConnection to simulate that the thread perform all display process. It works with QueuedConnection but I want the other behaviour

    I'm stopping the threads into the parents class.

    Note that it works with QueuedConnection.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: BlockingQueuedConnection hang

    Did you try to read the notification about threads and concurrency for the signals and slots? Look here and check special note about signaling in different modes. Shortly, only queued mode is eligible for inter-thread communications.

    Regards,
    -- Tanuki

    per cauda vel vaculus cauda

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BlockingQueuedConnection hang

    Hi,

    As I read in the BlockingQueuedConnection, it's the same as QueuedConnection but the emmiter thread stops until the other thread(main thread in this case) finish the execution of the slot.

    The threads are running in "run" method, and don't have it's own event loop. Maybe it's not possible because it don't have an event loop?

    Thanks,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: BlockingQueuedConnection hang

    Not really.

    Each thread can have its own event loop. The initial thread starts its event loops using QCoreApplication::exec(); other threads can start an event loop using QThread::exec(). Like QCoreApplication, QThread provides an exit(int) function and a quit() slot.

    An event loop in a thread makes it possible for the thread to use certain non-GUI Qt classes that require the presence of an event loop (such as QTimer, QTcpSocket, and QProcess). It also makes it possible to connect signals from any threads to slots of a specific thread. This is explained in more detail in the Signals and Slots Across Threads section below.
    The trick comes that you should process those events manually or rely upon
    Qt Code:
    1. exec()
    To copy to clipboard, switch view to plain text mode 
    method from
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    Just check if you call it at the end of the run. Also if you want something in separate thread - then declare, create, bind, use and destroy that inside
    Qt Code:
    1. run()
    To copy to clipboard, switch view to plain text mode 
    .

    Also, a piece of code will help to detect the mistake.

    Good luck,
    -- Tanuki

    per cauda vel vaculus cauda

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BlockingQueuedConnection hang

    Hi,

    I know that using exec will make the thread to have it's own event loop, but I'm using the thread on the other behaviour. Practically it's a infinite loop(until a boolean value goes false) and the thread waits when there is no data to process. So in this case I can't use an event loop into the thread.
    Òscar Llarch i Galán

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: BlockingQueuedConnection hang

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    I know that using exec will make the thread to have it's own event loop, but I'm using the thread on the other behaviour. Practically it's a infinite loop(until a boolean value goes false) and the thread waits when there is no data to process. So in this case I can't use an event loop into the thread.
    Yes You can. In example something like this :
    Qt Code:
    1. class MySuperWorker : public QThread
    2. {
    3. .
    4. .
    5. .
    6. protected:
    7. void run();
    8. slots :
    9. void makePartOfJob();
    10. }
    11.  
    12. void MySuperWork::run()
    13. {
    14. .
    15. .
    16. .
    17. //activate one part of job
    18. QTimer::singleShot(0,this,SLOT(makePartOfJob()));
    19. exec();
    20. }
    21.  
    22. void MySuperWork::makePartOfJob()
    23. {
    24. //
    25. //here do a part of job
    26. //one course of old while loop
    27. //
    28. if( !end_of_job )
    29. //activate next part of job
    30. QTimer::singleShot(0,this,SLOT(makePartOfJob()));
    31. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 6th November 2009, 19:33
  2. Replies: 2
    Last Post: 27th June 2008, 20:02
  3. QFileDialog hang ups
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2007, 03:56
  4. QHttp::get seems to hang on request
    By last2kn0 in forum Qt Programming
    Replies: 16
    Last Post: 14th October 2007, 23:00

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.