Thank you wysota for your reply.
But could you please be more specific?
Someone suggested me with the following code:
int Dlg::exec()
{
functionToBeCalled();
}
int Dlg::exec()
{
functionToBeCalled();
return QDialog::exec();
}
To copy to clipboard, switch view to plain text mode
but the problem is that, my functionToBeCalled() is a function that does some animation (inside a QGraphicsView), so if we call this function before the exec() function, the user will not see the animation.
I have got an idea but could not make it work. In the following code, I re-implement completely the exec() function, by just copying the source code of QDialog::exec() and adding functionToBeCalled() after show():
int Dlg::exec()
{
if (d->eventLoop) {
qWarning("QDialog::exec: Recursive call detected");
return -1;
}
bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_DeleteOnClose, false);
d->resetModalitySetByOpen();
bool wasShowModal = testAttribute(Qt::WA_ShowModal);
setAttribute(Qt::WA_ShowModal, true);
setResult(0);
//On Windows Mobile we create an empty menu to hide the current menu
#ifdef Q_WS_WINCE_WM
#ifndef QT_NO_MENUBAR
if (!findChild<QMenuBar *>())
if (qt_wince_is_smartphone()) {
menuBar->setDefaultAction(doneAction);
connect(doneAction, SIGNAL(triggered()), this, SLOT(_q_doneAction()));
}
#endif //QT_NO_MENUBAR
#endif //Q_WS_WINCE_WM
bool showSystemDialogFullScreen = false;
#ifdef Q_OS_SYMBIAN
if (qobject_cast<QFileDialog *>(this) || qobject_cast<QFontDialog *>(this) ||
qobject_cast<QWizard *>(this)) {
showSystemDialogFullScreen = true;
}
#endif // Q_OS_SYMBIAN
if (showSystemDialogFullScreen) {
setWindowFlags(windowFlags() | Qt::WindowSoftkeysVisibleHint);
setWindowState(Qt::WindowFullScreen);
}
show();
/****** MY ANIMATION HERE *******/
functionToBeCalled();
#ifdef Q_WS_MAC
d->mac_nativeDialogModalHelp();
#endif
d->eventLoop = &eventLoop;
QPointer<QDialog> guard = this;
if (guard.isNull())
d->eventLoop = 0;
setAttribute(Qt::WA_ShowModal, wasShowModal);
int res = result();
if (deleteOnClose)
delete this;
#ifdef Q_WS_WINCE_WM
#ifndef QT_NO_MENUBAR
else if (menuBar)
delete menuBar;
#endif //QT_NO_MENUBAR
#endif //Q_WS_WINCE_WM
return res;
}
int Dlg::exec()
{
Q_D(QDialog);
if (d->eventLoop) {
qWarning("QDialog::exec: Recursive call detected");
return -1;
}
bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_DeleteOnClose, false);
d->resetModalitySetByOpen();
bool wasShowModal = testAttribute(Qt::WA_ShowModal);
setAttribute(Qt::WA_ShowModal, true);
setResult(0);
//On Windows Mobile we create an empty menu to hide the current menu
#ifdef Q_WS_WINCE_WM
#ifndef QT_NO_MENUBAR
QMenuBar *menuBar = 0;
if (!findChild<QMenuBar *>())
menuBar = new QMenuBar(this);
if (qt_wince_is_smartphone()) {
QAction *doneAction = new QAction(tr("Done"), this);
menuBar->setDefaultAction(doneAction);
connect(doneAction, SIGNAL(triggered()), this, SLOT(_q_doneAction()));
}
#endif //QT_NO_MENUBAR
#endif //Q_WS_WINCE_WM
bool showSystemDialogFullScreen = false;
#ifdef Q_OS_SYMBIAN
if (qobject_cast<QFileDialog *>(this) || qobject_cast<QFontDialog *>(this) ||
qobject_cast<QWizard *>(this)) {
showSystemDialogFullScreen = true;
}
#endif // Q_OS_SYMBIAN
if (showSystemDialogFullScreen) {
setWindowFlags(windowFlags() | Qt::WindowSoftkeysVisibleHint);
setWindowState(Qt::WindowFullScreen);
}
show();
/****** MY ANIMATION HERE *******/
functionToBeCalled();
#ifdef Q_WS_MAC
d->mac_nativeDialogModalHelp();
#endif
QEventLoop eventLoop;
d->eventLoop = &eventLoop;
QPointer<QDialog> guard = this;
(void) eventLoop.exec(QEventLoop::DialogExec);
if (guard.isNull())
return QDialog::Rejected;
d->eventLoop = 0;
setAttribute(Qt::WA_ShowModal, wasShowModal);
int res = result();
if (deleteOnClose)
delete this;
#ifdef Q_WS_WINCE_WM
#ifndef QT_NO_MENUBAR
else if (menuBar)
delete menuBar;
#endif //QT_NO_MENUBAR
#endif //Q_WS_WINCE_WM
return res;
}
To copy to clipboard, switch view to plain text mode
The first error I got is _'QDialog::d_func' : cannot access private member declared in class 'QDialog'_.
Hope somebody can help.
Have a nice day !
Bookmarks