Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is Thread stop right?
Forum Updated to NodeBB v4.3 + New Features

Is Thread stop right?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 395 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kien Bui
    wrote on last edited by
    #1

    Eg1:
    at MainForm:

    MainForm()
    {
        this->thread = NULL;
    }
    
    void start()
    {
        Worker *worker = new Worker();
        this->thread = new QThread();
        worker->moveToThread(thread);
        connect(thread, SIGNAL(started()), worker, SLOT(process()));
    }
    
    void stop()
    {
       if (thread != NULL)
        {
            if(thread->isRunning())
            {
                th_getBuild->quit();
                th_getBuild->wait();
                th_getBuild->deleteLater();
            }
        }
    }
    

    Eg2: It is Eg1. But class Worker has a method stop() (maybe slot), it also called immediately.
    stop() method rewrited:

    void stop()
    {
       if (thread != NULL)
        {
            if(thread->isRunning())
            {
                worker->stop();
                th_getBuild->quit();
                th_getBuild->wait();
                th_getBuild->deleteLater();
            }
        }
    }
    

    has it any problem?

    JonBJ 1 Reply Last reply
    0
    • K Kien Bui

      Eg1:
      at MainForm:

      MainForm()
      {
          this->thread = NULL;
      }
      
      void start()
      {
          Worker *worker = new Worker();
          this->thread = new QThread();
          worker->moveToThread(thread);
          connect(thread, SIGNAL(started()), worker, SLOT(process()));
      }
      
      void stop()
      {
         if (thread != NULL)
          {
              if(thread->isRunning())
              {
                  th_getBuild->quit();
                  th_getBuild->wait();
                  th_getBuild->deleteLater();
              }
          }
      }
      

      Eg2: It is Eg1. But class Worker has a method stop() (maybe slot), it also called immediately.
      stop() method rewrited:

      void stop()
      {
         if (thread != NULL)
          {
              if(thread->isRunning())
              {
                  worker->stop();
                  th_getBuild->quit();
                  th_getBuild->wait();
                  th_getBuild->deleteLater();
              }
          }
      }
      

      has it any problem?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Kien-Bui
      What is th_getBuild, and what relationship if any does it have to thread?

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved