Results 1 to 2 of 2

Thread: how to stop thread while thread is running?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2018
    Posts
    19
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default how to stop thread while thread is running?

    I have a Class DeviceManager:

    Qt Code:
    1. DeviceManager(QObject *parent) :
    2. QObject(parent)
    3. {
    4. thread = new QThread();
    5. this->moveToThread(thread);
    6. connect(thread, SIGNAL(started()), this, SLOT(autoDetect()));
    7. thread->start();
    8. }
    9.  
    10. void autoDetect()
    11. {
    12. ...
    13. emit addDevice();
    14. ...
    15. }
    To copy to clipboard, switch view to plain text mode 

    Class MainForm:
    Qt Code:
    1. MainForm(QObject *parent) :
    2. QObject(parent)
    3. {
    4. this->manager = new DeviceManager();
    5. connect(manager, SIGNAL(addDevice()), this, SLOT(slot()));
    6.  
    7. }
    8.  
    9. void refresh()
    10. {
    11. this->manager->deleteLater();
    12. this->manager = new DeviceManager();
    13. connect(manager, SIGNAL(addDevice()), this, SLOT(slot()));
    14. }
    To copy to clipboard, switch view to plain text mode 



    I have a problem is manager don't disconnect. When mainForm call refresh many time (eg: 3 times), then when slot() is executed 4 times.
    I think that the older manager's connect is disconnect or object can't deleted.
    I tried delete thread but I got message:
    QThread: Destroyed while thread is still running
    How to stop thread while thread is still running?
    Last edited by madawg; 30th May 2018 at 09:53.

Similar Threads

  1. Replies: 0
    Last Post: 7th December 2017, 19:33
  2. Replies: 1
    Last Post: 6th December 2015, 17:12
  3. Replies: 4
    Last Post: 17th October 2013, 12:12
  4. Replies: 4
    Last Post: 24th September 2012, 08:28
  5. Stop the thread
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 11:29

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.