Form show is not immediate
-
Application has many form.
fun1(){
Code A
form1.show();
Code B
}My problem is that until code B is not finished form1 is not show. Please tell me the solution for this.
-
Move Code B to another function and invoke it with a delay (for example, using signals and slots, or meta objects).
Alternatively, you can insert this line between show() and Code B:
@
qApp->processEvents();
@ -
My problem is that form should be shown first and in background the Code B should get executed.
-
#include<QDialog>
fun1(){
qDebug() << “Code A”;
w.show(); // Should display wait screen dialog
/* My problem is that wait screen is not shown immediately but shown after code B is executed. */
qDebug() << “Code B”; // Perform some calculations and read write to I/O device.
w.hide(); // Hide wait screen dialog
}
[quote author="sierdzio" date="1393410839"]Move Code B to another function and invoke it with a delay (for example, using signals and slots, or meta objects).Alternatively, you can insert this line between show() and Code B:
@
qApp->processEvents();
@[/quote] -
I recommend using the asynchronous approach (signals and slots). It makes the design clearer and avoids some problems when compared to sequential kind of thinking your snippet shows.
Also, please wrap your code in '@' tags.
-
Tried the asynchronous method but still the wait screen wont show up before code B gets executed.
-
Do you get any error messages? Is the event loop running? Are you using Qt::QueuedConnection for your signal-slot connection?
-
No i am not getting any error message. And i am not using Qt::QueuedConnection for my signal and slot.
-
Try it, then. Or invoke your slot using QTimer::singleShot().
-
Dear Sierdzio,
qApp->processEvents();
Was the solution to my problem.
Many thanks.