c++ - How to emit a signal with array parameter to another Thread -
i new qt , want emit signal qthread main thread few parameter. doesn't work. doing wrong?
//reader.h signals: void updatedata(quint16 fw, qstring serial, quint16 *calibration); //reader.cpp ... { quint16 calibration[8]; quint16 fw; qstring serialnumber; readdata(&fw, &serialnumber, calibration); // declaration: void reader::readdata(quint16 *fw, qstring *serial, quint16 *calibration) emit updatedata(fw, serialnumber, calibration); // in function parameters assigned correctly } //mainwindow.h public slots: void updatedata(quint16 fw, qstring serialnumber, quint16 *calibration); //mainwindow.cpp void mainwindow::updatedata(quint16 fw, qstring serialnumber, quint16 *calibration) { ui->lineeditfw->settext(qstring::number(fw)); // correct ui->lineeditserialnumber->settext(serialnumber); // correct ui->spinboxreg1->setvalue(calibration[0]); // incorrect! ui->spinboxreg2->setvalue(calibration[1]); // ..array calibration ui->spinboxreg3->setvalue(calibration[2]); // ..is filled ui->spinboxreg4->setvalue(calibration[3]); // ..random data! ui->spinboxreg5->setvalue(calibration[4]); ui->spinboxreg6->setvalue(calibration[5]); ui->spinboxreg7->setvalue(calibration[6]); ui->spinboxreg8->setvalue(calibration[7]); } //... init() { // other connection of thread , reader object //... connect(reader, signal(updatedata(quint16, qstring, quint16 *)), this, slot(updatedata(quint16, qstring, quint16 *))); //... reader->movetothread(readerthread); readerthread->start(); }
i tried array instead of pointer. didn't work well.
thanks.
calibration[8] on stack, destroyed when reader function returns. need make persistent (allocate on heap) still exists when signal delivered.
Comments
Post a Comment