Results 1 to 2 of 2

Thread: signal-slot connection requires thread must be QThread?

  1. #1
    Join Date
    Sep 2008
    Posts
    4
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question signal-slot connection requires thread must be QThread?

    Based on Qt document, "Qt provides thread support in the form of platform-independent threading classes, a thread-safe way of posting events, and signal-slot connections across threads.", I am wondering to make Qt signal-slot connection across threads work, do i have to make sure all the threads are created with QThread or Qt GUI thread?

    For example, i have a Qt GUI thread, and i have a library running in another thread (Win32 thread). and in my GUI program, i override some virtual functions provided by the library which act as the callback function (based on publish/subscribe pattern). so the codes in the overridden virtual functions are actually executed in the Win32 thread. can i emit signal in the overridden function and let the slot in Qt GUI thread to connect with it to make the Async calling work?

    Thanks
    Last edited by Bing; 10th September 2008 at 20:40.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal-slot connection requires thread must be QThread?

    Quote Originally Posted by Bing View Post
    can i emit signal in the overridden function and let the slot in Qt GUI thread to connect with it to make the Async calling work?
    I'm not sure us the automatic connections will work properly, but queued one should work. A queued signal is delivered using QCoreApplication::postEvent() which is thread-safe.

  3. The following user says thank you to jacek for this useful post:

    Bing (12th September 2008)

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. QThread and QSlot
    By Xaar in forum Qt Programming
    Replies: 5
    Last Post: 6th December 2007, 21:37
  3. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 5th November 2007, 23:56
  4. Replies: 3
    Last Post: 15th April 2007, 19:16

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.