I am newbee at QThreads and a problem that I am suspicious of deleting the objects when the program finishes.My program has a class that derived from QObject:
class My_application: public QCoreApplication{
....
....
};
class My_Class: public QObject{
...
...
};
void My_Class::process{
QTimer timer=new QTimer();
timer->setInterval(time);
connect(timer,SIGNAL(timeout()),this,SLOT(dowork()));
timer->start();
}
My_application::My_application:QCoreApplication{
my_class=new My_Class();
QThread thread=new QThread();
my_class->moveToThread(thread);
connect(thread,SIGNAL(started()),my_class,SLOT(process())) ;
connect(my_class,SIGNAL(finished()),thread,SLOT(quit())) ;
connect(thread,SIGNAL(finished()),thread,SLOT(deletelater())) ;
connect(my_class,SIGNAL(finished()),my_class,SLOT(deletelater())) ;
}
void My_Class::dowork(){
//here doing the work with timer elapsed.Doing work with some buffer and send data
//
}
If I stop my program I see that some objects are not deleted correctly and my program does not work when I restart it.Actually I am not so familiar with Qt threads and i wonder when does the destructor of My_Class will be called? and am i doing the wrong thing?