Results 1 to 8 of 8

Thread: QThread deleteLater()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThread deleteLater()

    Quote Originally Posted by doggrant View Post
    Can any qobject have an eventloop?
    Objects don't have event loop. Threads do.

    Because some of the cleardown routines for this class take time to complete, I run them in a thread that is a member of that Card object.
    That's probably not a very good idea.

    Just after creating the thread, but this still fails to call the qthread destructor until my app exits.
    Do you have an event loop running?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread deleteLater()

    Because some of the cleardown routines for this class take time to complete, I run them in a thread that is a member of that Card object.
    That's probably not a very good idea.
    I know this might not be the best idea, but since i have no control over the external library, which is slow, I need to use a thread to call the external routines.

    What I have is the following:

    QMainWindow, which has an event loop (Have called exec() is here)
    |
    |_ _ _ Hotswap QThread that uses waitformultiple objects to wait for events from an external library.
    Exec() not called here, since my own thread processing is in run()
    |
    |_ _ _ When an event fires in the hotswap thread, a card object is created, and
    after getting info about the card, the cleanup thread is run.
    Note: The card object will still be alive after the cleanup thread has been executed.


    So what I really need is a way to call delete on the cleanup thread, when the finished() signal fires, but i'm not sure how to do this in this instance.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThread deleteLater()

    Quote Originally Posted by doggrant View Post
    I know this might not be the best idea, but since i have no control over the external library, which is slow, I need to use a thread to call the external routines.
    No, you don't. Unless you want to crash your app sooner or later but there are easier ways to do this than allowing multiple threads to access the same data.

    So what I really need is a way to call delete on the cleanup thread, when the finished() signal fires, but i'm not sure how to do this in this instance.
    Make the QThread object controlling the cleanup thread live in the main thread so that its slot gets executed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread deleteLater()

    Hi,

    when looking at the stack there was nothing there, the thread had exited, unless i should have been looking at the stacks of other threads involved.

    On a good(ish) note, i tried the same application today, and the problem does not occur when debugging. I beleive it may be a timing issue when debugging, but will not be able to look at it again unless it re-occurs!

    David

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QThread deleteLater()

    The QThread should be on the main thread anyway - you're not moving it anywhere, are you?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Let QThread delete itself with deleteLater();
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2010, 16:48
  2. To use or not to use: deleteLater()
    By codeslicer in forum Qt Programming
    Replies: 11
    Last Post: 11th July 2009, 21:43
  3. QT deleteLater again.
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2008, 22:36
  4. Qt Deletelater
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2008, 16:58
  5. DeleteLater works... but why?
    By TheGrimace in forum Qt Programming
    Replies: 11
    Last Post: 6th June 2007, 15:14

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.