c++ - Qt slot from thread called more than once -
this question has answer here:
i have created class calculationmanager has public slot process() emitting signal finished().
void calculationmanager::process() { cout << "calc fft: process()" << endl; ... emit finished(); }
this used qthread gui (calculationmanager qscopedpointer)
void mainwindow::on_pushbuttonstartfft_clicked() { cout << "on_pushbuttonstartfft_clicked()" << endl; ... calculationmanager->movetothread(thread); connect(thread, signal (started()), calculationmanager.data(), slot (process())); connect(calculationmanager.data(), signal (finished()), thread, slot (quit())); connect(calculationmanager.data(), signal (finished()), this, slot (getresultsandplot())); cout << "fft thread started." << endl; thread->start(); }
with slot plots
void mainwindow::getresultsandplot() { fftaction doshift = static_cast<fftaction>(calculationmanager->shiftbeforefft()); updateplotdata(ui->qplot1, calculationmanager->data(doshift) ); cout << "update plots" << endl; }
at startup of gui function called. , output expected:
on_pushbuttonstartfft_clicked() fft thread started. calc fft: process() update plots
however every further click on buttons calls process multiple times , getresultsandplot() more often. have not clue why happens. how can debug or solve ?
on_pushbuttonstartfft_clicked() fft thread started. calc fft: process() calc fft: process() update plots update plots update plots update plots on_pushbuttonstartfft_clicked() fft thread started. calc fft: process() calc fft: process() calc fft: process() update plots update plots update plots update plots update plots update plots update plots update plots update plots
every time click button, create connections
connect(thread, signal (started()), calculationmanager.data(), slot (process())); connect(calculationmanager.data(), signal (finished()), thread, slot (quit())); connect(calculationmanager.data(), signal (finished()), this, slot (getresultsandplot()));
so, after first click there 1 connection , slot process()
called once. after second click there 2 connections , slot called twice. , on. make connections outside slot on_pushbuttonstartfft_clicked()
.
Comments
Post a Comment