Results 1 to 9 of 9

Thread: Moving QObject to QThread causes signals to stop working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    20
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Moving QObject to QThread causes signals to stop working

    I know that QThreads are a tricky issue for most. I've read through a lot of examples and documentation to setup my threading correctly under QT. The 2 methods seem to be sub-classing QThread (which although the documentation says to do this, it is apparently the incorrect way) and the other is subclassing QObject and then moving it to a thread. Trying both methods I was unable to get a simple signal in the thread to connect to a slot in my main thread.

    For the first method if I did not use moveToThread(this) in the subclassed QThread constructor, it would not execute in a new thread, but the signals worked. Using moveToThread(this) caused the connection to be broken in some way.

    Trying it the 2nd method, my signals in the worker object worked until I moved them to a QThread.

    Are there any known issues with using QThread under QT 4.6.3 and compiling with MSVC 2010 on Win7 x64( the app is compiled as 32-bit)?

    The signal I'm emitting is a QString (declare as: void StringSignal(QString&);, used as: emit StringSignal(QString("Hello"))
    In the first method the connection is made as:
    Qt Code:
    1. connect(&thread,SIGNAL(StringSignal(QString&)),this,SLOT(SignalSlot(QString&)));)
    To copy to clipboard, switch view to plain text mode 

    My code isn't any different than the Mandelbrot example (for the first method I tried). I call a function in the QThread that sets some values and either starts the thread if it isn't running or wakes the QWaitCondition.
    Last edited by Ban-chan; 13th July 2010 at 16:55.

Similar Threads

  1. How to stop QThread?
    By vespasianvs in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2010, 06:42
  2. [QThread] Function calling after thread.stop()
    By Macok in forum Qt Programming
    Replies: 4
    Last Post: 7th February 2009, 13:33
  3. Replies: 1
    Last Post: 10th October 2007, 10:11
  4. Stop window moving when clicking LMB
    By steg90 in forum Qt Programming
    Replies: 11
    Last Post: 11th June 2007, 10:59
  5. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.