I have a thread (associated with a button) that starts two threads in turn, opens and closes them. And when I "press" the button, then the main thread closes for me and the child one still works (and it works until the program is closed).
Enable main stream:
void MainWindow::on_pB_Cickl_toggled(bool checked) { qDebug() << "on_pB_Cickl_toggled: " << "Зашли"; if(checked == true) { ui->pB_run_stypen->setEnabled(false); ui->pB_Statrt->setEnabled(false); ui->pB_Stop->setEnabled(false); thread_schet = new QThread(); mythread_otpr_schet = new MyThread_otpr_Schet(); connect(thread_schet,SIGNAL(started()),mythread_otpr_schet,SLOT(Start())); mythread_otpr_schet->moveToThread(thread_schet); thread_schet->start(); } if(checked == false) { qDebug() << "checked == false : " << "Вышли " <<checked ; thread_schet->requestInterruption(); thread_schet->quit(); chista_per = false; ui->pB_run_stypen->setEnabled(true); ui->pB_Statrt->setEnabled(true); ui->pB_Stop->setEnabled(true); } } A child thread that launches two threads in turn:
void MyThread_otpr_Schet::Start(){ chista_per = false; pB_timers = new QTimer(this); connect(pB_timers,SIGNAL(timeout()),this,SLOT(slotCickl_period())); pB_timers->start(3000); } void MyThread_otpr_Schet::slotCickl_period() { qDebug() << "slotCickl_period: " << "тут"; chista_per = !chista_per ; if(chista_per == true) { if(D_Start == true) { thread_OTKL->requestInterruption(); thread_OTKL->quit(); } thread_VKL = new QThread(); my_potok_vklych = new MyThr_otpr_Sch_vkl(); connect(thread_VKL,SIGNAL(started()),my_potok_vklych,SLOT(Start())); my_potok_vklych->moveToThread(thread_VKL); thread_VKL->start(); D_Start = true; } if(chista_per == false) { if(D_Start == true) { thread_VKL->requestInterruption(); thread_VKL->quit(); } thread_OTKL = new QThread(); my_potok_otklych = new MyThr_otpr_Sch_otkl(); connect(thread_OTKL,SIGNAL(started()),my_potok_otklych,SLOT(Start())); my_potok_otklych->moveToThread(thread_OTKL); thread_OTKL->start(); D_Start = true; } } And here is the problem - the child thread is closed and the daughter of the child is not (more precisely, one of them).
I implement a multithreading through QThread.
I understand that it is not caused by the "closing" of the thread. But I did not understand and did not find in the documentation a signal to close the stream.
thread_VKL->start();Since no procedure has been established in this thread, there is no message processing loop either. - Chorkov