I am working on Qt 5.5 and have created a seperate thread that uses 3rd party library APIs. This Api function which when executes consumes all resources and does not allow any other function to execute in that thread.
This new thread starts with a click of button say "Start" and I just do not know how to stop or kill thread when I press stop button. Below is my sample example
threadWorking = new QThread();
workHeavy = new WorkingHard;
workHeavy->moveToThread( threadWorking );
connect( threadWorking, SIGNAL( started() ), workHeavy, SLOT( slotStartStream() ) );
connect( workHeavy, SIGNAL( sigStopStream() ), threadWorking, SLOT( quit() ) );
connect( workHeavy, SIGNAL( sigStopStream() ), workHeavy, SLOT(deleteLater() ) );
connect( threadWorking, SIGNAL( finished() ), threadWorking, SLOT(deleteLater() ) );
connect( workHeavy, SIGNAL( sigStartStream() ), this, SLOT( slotTrueStreamRun() ) );
connect( workHeavy, SIGNAL( sigStopStream() ), this, SLOT( slotFalseStreamRun() ) );
connect( this, SIGNAL( sigMopsCamStopCmd() ), workHeavy, SLOT(slotStopStream() ) );
threadWorking->start();
Also// void WorkingHard::slotStartStream()
{
g_main_loop_run( gloop ); // this consumes all resources.
}
void WorkingHard::slotStopStream()
{
// clean up mess
g_main_loop_quit( gloop );
gst_element_set_state (pipeline, GST_STATE_NULL);
// g_main_loop_quit( gloop );
releaseMemory();
}
Please advice me to kill thread based on id or something else. One thing is clear is that I cant go inside thread when function is running.
As folks have suggested to use terminate. If I use terminate() do I still need to free memory as I pointed in fiunction slotStopStream??