Important: Please read the Qt Code of Conduct -

Question regarding Mandelbrot threading Example

  • Hi all,

    I have two questions about Mandelbrot threading Example (

    1. I implemented a thread similar to RenderThread. when I step in my code, I noticed that after thread wake up, it is extremely slow stepping from the last line of code to the first line of code inside run() forever loop. The last two lines of code in run() forever loop are:
      restart = false;
      the first line of code in run() forever loop is

    why is it so slow, is it related to forever?

    1. who will call RenderThread::~RenderThread(), it is now shown in the example? more general question is how to delete a worker thread.


  • To delete a QThread you usually do something like this:
    connect(myThread, SIGNAL(finished()), myThread, SLOT(deleteLater()));

  • sorry, I didn't make my question clear. in Mandelbrot threading Example, main thread can just call ~RenderThread() to destroy this thread since run() is checking abort flag.
    KA510's signal-slot connection seems only for self destruction. how can I delete worker thread from main thread if the worker thread's run() is only calling exec(), there is no flag checking there?

  • That depends on the approach you're using. If you are using the "worker object approach":, or if you're using the old subclassing approach (which you should avoid in most cases). If you have a look at the example code provided in the article on the general usage of QThread (see link above) I think your problem should resolve itself. If you have more questions I'll be glad to try and help you.

  • Another question is in this example we put thread into sleep when it is not used. Another option is to delete the thread, then recreate and run a new thread when it is needed.
    Personally I prefer the sleep option since I think thread deletion/creation is more expensive, but I did see thread deletion/creation examples some other places. Is there any experiment to prove which one is better? I don't know how to use profiler to check the two options.


Log in to reply