multithreading - Qt signal and slot issue -


i have issue signals , slots, want use backgroundworker thread. suppose send signal few double values should updated in main gui. code compiles , thread starts gui not updating values.

first gui slot:

void mainwindow::slot_set_values(double ptm_temp, double ptm_hv, double heat_temp, double nomtemp, double current, double voltage) {     ui->pmtvaluelabel->settext(qstring::number(ptm_temp));     ui->hvvaluelabel->settext(qstring::number(ptm_hv));     ui->heatvaluelabel->settext(qstring::number(heat_temp));     ui->nomvaluelabel->settext(qstring::number(nomtemp));     ui->currenvaluelabel->settext(qstring::number(current));     ui->vvaluelabel->settext(qstring::number(voltage));  } 

the worker code:

void dworker::run() {     qsrand(qdatetime::currentdatetime().totime_t());     mdata.set_pmt_temp(qrand()%100);     mdata.set_pmt_hv(qrand()%100);     mdata.set_heat_opt_temp(qrand()%100);     mdata.set_heat_nominal_temp(qrand()%100);      (int = 0; i<100; i++)     {         double pmt_tmp = mdata.get_pmt_temp();         double hv = mdata.get_pmt_hv();         double heat_temp = mdata.get_heat_opt_temp();         double heat_nom = mdata.get_heat_nominal_temp();          emit set_values(pmt_tmp,hv,heat_temp,heat_nom,0,0);         emit set_pmt();          qthread::msleep(1000);         qdebug() << "test vom thread " << i;     } } 

and connect statements:

connect(workerthread,signal(set_values(double,double,double,double,double,double)), this,slot(slot_set_values(double,double,double,double,double,double)));  connect(workerthread,signal(set_pmt()),this,slot(slot_set_pmt()));  

if object sends signal , receiver object in different threads, should connect qt::queuedconnection (docs here)

so, change connects this:

connect(workerthread,signal(set_values(double,double,double,double,double,double)), this,slot(slot_set_values(double,double,double,double,double,double)),qt::queuedconnection); connect(workerthread,signal(set_pmt()),this,slot(slot_set_pmt()),qt::queuedconnection);  

additionally, can try check via qdebug, receiving in slot:

qdebug()<<"my slot called,"<<ptm_temp<<" "<<ptm_hv<<" "<<heat_temp<<" "<<nomtemp<<" "<<current<<" "<<voltage; 

also, imperative have signal-slots, in header of derived class q_object macro


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -