Unsolved How to run background process when a Dialog is showed
-
I tried to run a process when a dialog is showed, But it didnt work . I want to show an dialog and at the same time i want to run the background process also , in which way this can be done ?
-
hi
@ManiRon said in How to run background process when a Dialog is showed:I tried to run a process when a dialog is showed
how ?
@ManiRon said in How to run background process when a Dialog is showed:
But it didnt work
more precisely ?
@ManiRon said in How to run background process when a Dialog is showed:
i want to run the background process also
reimplement the showEvent and run your task/code in QConcurent or QThread
-
@LeLev said in How to run background process when a Dialog is showed:
reimplement the showEvent and run your task/code in QConcurent or QThread
No need to use threads here as QProcess has an asynchronous API
-
@ManiRon said in How to run background process when a Dialog is showed:
in which way this can be done ?
Using QProcess. So, please show what you did and tell us what did not work.
-
@jsulm said in How to run background process when a Dialog is showed:
No need to use threads here as QProcess has an asynchronous API
sorry, my bad, i thought @ManiRon was referring to some code/method by 'process'
-
@LeLev said in How to run background process when a Dialog is showed:
No need to use threads here as QProcess has an asynchronous API
Process means in this case i meant the tasks that are done by me
-
Hi
What do you want to run in the background ?
Is it a single function ? or its some class that can process something?What did you already try ?
Show some code.
-
@ManiRon said in How to run background process when a Dialog is showed:
Process means in this case i meant the tasks that are done by me
Don't forget that if you don't want/need to have a separate thread, you can show a modal dialog but not block by using
modal.show()
rather thanmodal.exec()
, so you can still do work while modal displayed. -
@JonB said in How to run background process when a Dialog is showed:
while
Actually i tried something like this
qDebug("Before SHow"); Modal.show(); qDebug("After SHow");
Similarly for Exec
qDebug("Before SHow"); Modal.exec(); qDebug("After SHow");
But what i observed was the first print was coming and later print was coming only when the Modal was closed
-
@ManiRon
Hi
It's important to understand that
modal.exec() is a socalled blocking call.
It spins an event loop in there and
will first return once dialog is closed.That means it will NOT execute the next line after it dialog is gone.
--
modal.show() on the other hand is NOT blocking and
will execute the next line as soon as show() has run and while the dialog is still being displayed. -
This post is deleted! -
@mrjj I checked and it worked the way you specified
-
@ManiRon
Ok that is good. Its an important difference between
show() and exec() -
-
@ManiRon
Just to be clear: it is precisely becausemodal.exec()
does not return to the caller till after the dialog has been closed, whilemodal.show()
lets the caller continue, (and you will later react via signal/slot to user closing dialog, documentation describes this behaviour) that I am saying you may be able to useshow()
so that your calling code can continue and do other processing without the need to create a separate thread. It depends on what other processing you need to do, it was just a heads-up.