Results 1 to 17 of 17

Thread: moveToThread and connecting Signals

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: moveToThread and connecting Signals

    Ok, so if I decide to use QMutex, all I have to do is to guard the setThreadToNULL slot and the destructor.

    The mutex will prevent(block) the thread from deleting, while destructor is executing. Right?
    Last edited by Qiieha; 14th August 2015 at 13:29.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: moveToThread and connecting Signals

    Yes, but I don't really understand why you need to set the variable to null and not just always delete the thread at the end?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: moveToThread and connecting Signals

    Cause I think deleting a QThread while executing is dangerous, isn't it?

    If I don't finish the threading properly the app chrashes.

    Qt Code:
    1. if(worker){//thats the pointer that is checked
    2. worker->interrupt();//a custom method that finishes the run method in object Worker, which is moved to QThread
    3. thread->quit();
    4. if(!thread->wait(3000))
    5. {
    6. thread->terminate();
    7. thread->wait();
    8. }
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Qiieha; 14th August 2015 at 16:42.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: moveToThread and connecting Signals

    Quote Originally Posted by Qiieha View Post
    Cause I think deleting a QThread while executing is dangerous, isn't it?
    Yes, but you can always do the same operation:
    - you tell the thread to stop
    - you wait for the thread to stop
    - you delete the thread object

    No need for the thread to "remove itself".

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Qiieha (17th August 2015)

  6. #5
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: moveToThread and connecting Signals

    Ok, that's true.
    Thank you for explanations and tips concerning threading behaviour, Connecting-Types, etc.
    Your support is great.

Similar Threads

  1. Connecting signals and slots from different process
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2014, 15:59
  2. Connecting Qml signals to Qt
    By mots_g in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2011, 11:37
  3. Connecting QML signals with Qt slots
    By KIBSOFT in forum Qt Quick
    Replies: 1
    Last Post: 15th November 2010, 09:18
  4. Connecting signals and slots help pls
    By bod in forum Qt Programming
    Replies: 9
    Last Post: 1st July 2008, 15:01
  5. QHttp signals not connecting...
    By trobbins0000 in forum Newbie
    Replies: 1
    Last Post: 27th February 2007, 02:45

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.