PDA

View Full Version : QThread not stopping



vitalic
14th May 2020, 13:02
Hallo,

i created a program which has a button "scan" (scan DAB frequencies) and after all is finished list output in a QWidgetList. This was working without problems.

Now to inform the user about the progress of the scan I added a progressbar, which also works. To make this work I added a QThread for the scan function, but now if 100% is reached, the list is not updated, it stays empty. It gets filled when I hit "scan" again.

Already tried to stop the thread with a boolean.



void Dialog::on_btnDabScanFreq_clicked()
{

connect(&mScan,&Scan::progress_scan_dab,this,&Dialog::prog_bar_dab_valueChanged);

QFuture<void> scan_dab = QtConcurrent::run(&this->mScan,&Scan::dab_scan_wrapped);

ui->list_dab->clear();

for(int i = 0; i < mScan.dab_vec_vec.size(); i++){

ui->list_dab->addItem(mScan.dab_vec_vec[i][0]);
}
}


To make the thread work i had to wrap the called function:



void Scan::dab_scan_wrapped(){

forever{

if(mStop_dab_scan) break;

int devfd = -1;
int console = -1;
int running = -1;

Scan::media_scan_dabfrequencies("/dev/dab0",devfd,console,running);
}
}


The boolean switch is triggered, when 100% is reached:



if(prog_bar_dab == 100){
mStop_dab_scan = true;
}


Which function needs to be stopped to stop the thread? The wrapper function which is called by button scan, or the real scan function?

The "real" scan function writes it's result to dab_vec_vec.