PDA

View Full Version : execute function after widget is displayed.



quain
6th December 2010, 19:55
Hello.

I have a litle problem.
For testing purposes imagine a simple app witch a single button.
Clicking this button creates new window (basic QDialog), that contains fiew QLineEdits and QLabel's.

Code for that window also contains a time - consuming function.

Problem is: i would like to deley execution of this function till mentioned window is fully drawn.

Currently function is exeuted before window appears, so - more time this function needs - more time it takes to show my window.

My target is, as i have mentioned:
Application starts -> user clicks on the button -> new (children) window appears -> function included in this winow code is executed.

Thanks in advance for any help :)

PS:
I hope my English is readable enough.

ChrisW67
6th December 2010, 21:13
You can use a 0 millisecond single shot timer started from the constructor of the dialog to call the function (as a slot) after the program returns to the event loop.


MyDialog()
{
...
QTimer::singleShot(0, this, SLOT(doLongRunningThings()));
}

/* public or private slot */
void doLongRunningThings()
{
}

quain
6th December 2010, 21:36
Thank you very much :)

You idea work's perfect in my case.