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.

Qt Code:
  1. void Dialog::on_btnDabScanFreq_clicked()
  2. {
  3.  
  4. connect(&mScan,&Scan::progress_scan_dab,this,&Dialog::prog_bar_dab_valueChanged);
  5.  
  6. QFuture<void> scan_dab = QtConcurrent::run(&this->mScan,&Scan::dab_scan_wrapped);
  7.  
  8. ui->list_dab->clear();
  9.  
  10. for(int i = 0; i < mScan.dab_vec_vec.size(); i++){
  11.  
  12. ui->list_dab->addItem(mScan.dab_vec_vec[i][0]);
  13. }
  14. }
To copy to clipboard, switch view to plain text mode 

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

Qt Code:
  1. void Scan::dab_scan_wrapped(){
  2.  
  3. forever{
  4.  
  5. if(mStop_dab_scan) break;
  6.  
  7. int devfd = -1;
  8. int console = -1;
  9. int running = -1;
  10.  
  11. Scan::media_scan_dabfrequencies("/dev/dab0",devfd,console,running);
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 

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

Qt Code:
  1. if(prog_bar_dab == 100){
  2. mStop_dab_scan = true;
  3. }
To copy to clipboard, switch view to plain text mode 

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.