Great! That is the best answer I have found !!,Thank you very much ))
I write a test program for it:
#include <QApplication>
#include <QString>
#include <QTimer>
#include <QDebug>
#include <QMetaObject>
#include <QThread>
#include <QDialog>
{
Q_OBJECT
public:
Object(){qDebug()<<"** Object contruct **";}
~Object(){qDebug()<<"** Object destruct **";}
};
class DialogLevel3
: public QDialog {
Q_OBJECT
public:
setWindowTitle("DialogLevel3");
QTimer::singleShot(1000,
this,
SLOT(f
()));
}
public slots:
void f(){
qDebug()<<"[ DialogLevel3"<<QThread::currentThread() <<" ]";
}
};
class DialogLevel2
: public QDialog {
Q_OBJECT
public:
setWindowTitle("DialogLevel2");
}
public slots:
void init(){
object = new Object;
qDebug()<<"starting eventloop level2";
QTimer::singleShot(1000,
this,
SLOT(f
()));
exec();
qDebug()<<"return to level1";
}
void f(){
qDebug()<<"[ DialogLevel2"<<QThread::currentThread()<<" ]";
qDebug()<<"call object->deleteLater";
object->deleteLater();
DialogLevel3 dlg2;
qDebug()<<"starting eventloop level3";
dlg2.exec();
qDebug()<<"return to level2";
}
private:
Object *object;
};
int main(int argc,char* argv[])
{
qDebug()<<"[ mainthread"<<QThread::currentThread()<<" ]";
DialogLevel2 dlg1;
QMetaObject::invokeMethod(&dlg1,
"init",Qt
::QueuedConnection);
qDebug()<<"starting eventloop level1";
app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QString>
#include <QTimer>
#include <QDebug>
#include <QMetaObject>
#include <QThread>
#include <QDialog>
class Object : public QObject
{
Q_OBJECT
public:
Object(){qDebug()<<"** Object contruct **";}
~Object(){qDebug()<<"** Object destruct **";}
};
class DialogLevel3 : public QDialog
{
Q_OBJECT
public:
DialogLevel3():QDialog(){
setWindowTitle("DialogLevel3");
QTimer::singleShot(1000, this, SLOT(f()));
}
public slots:
void f(){
qDebug()<<"[ DialogLevel3"<<QThread::currentThread() <<" ]";
}
};
class DialogLevel2 : public QDialog
{
Q_OBJECT
public:
DialogLevel2():QDialog(){
setWindowTitle("DialogLevel2");
}
public slots:
void init(){
object = new Object;
qDebug()<<"starting eventloop level2";
QTimer::singleShot(1000, this, SLOT(f()));
exec();
qDebug()<<"return to level1";
}
void f(){
qDebug()<<"[ DialogLevel2"<<QThread::currentThread()<<" ]";
qDebug()<<"call object->deleteLater";
object->deleteLater();
DialogLevel3 dlg2;
qDebug()<<"starting eventloop level3";
dlg2.exec();
qDebug()<<"return to level2";
}
private:
Object *object;
};
int main(int argc,char* argv[])
{
QApplication app(argc, argv);
qDebug()<<"[ mainthread"<<QThread::currentThread()<<" ]";
DialogLevel2 dlg1;
QMetaObject::invokeMethod(&dlg1, "init",Qt::QueuedConnection);
qDebug()<<"starting eventloop level1";
app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks