c++ - Qt Object deleted but signal is not disconnected -
in topic told when qobject deleted active connections deleted. have case below:
work* work = new work();//->work derived qobject worker* worker = new worker(work);//->worker derived qthread , has ownership of work connect(work, signal(percentagecomplete(int)), progressdialog, slot(setvalue(int))); connect(worker, signal(finished()), worker, slot(deletelater())); progressdialog->show(); worker->start();
in worker's destructor have :
worker::~worker(void){ if(work != nullptr){ work->deletelater(); } }
i %100 sure work deleted. can see breakpoint. can see qobjects desctructor call.
but how deleted work object still receiving signal "percentage complete". , because deleted ,causing crush.
i want ask why signals not disconnected object deleted?
a second question in worker's destructor work->deletelater();
or delete work;
correct?
why dont use disconnect() disconnect connected slots/signals ? can call function in destructor.here have solution similar topic
Comments
Post a Comment