Problem with a modal dialog connecting with a process
-
Hi, everyone.
I have created a dialog where a button's clicked method is connected with a slot to stop the process.
When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.It seems I have to run the process in a new thread, is it?
Could I run the dialog in a new thread?Thank in advance.
-
Hi, everyone.
I have created a dialog where a button's clicked method is connected with a slot to stop the process.
When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.It seems I have to run the process in a new thread, is it?
Could I run the dialog in a new thread?Thank in advance.
Please provide a minimal, compilable example of your problem.
How do you try to stop the process - I don't see a function in the documenation. There is just a function/slot to kill the process without any chance for the process to handle it somehow. -
Please provide a minimal, compilable example of your problem.
How do you try to stop the process - I don't see a function in the documenation. There is just a function/slot to kill the process without any chance for the process to handle it somehow.void Run(bool bExec)
{while (bExec)
{
///Execute process
}
}main:
//setup dialog
//connect dialog button clicked to slot cancel
dialog->show();cancel slot:
//update bool exec to falseuser should be able to cancel the process by clicking the cancel button
-
void Run(bool bExec)
{while (bExec)
{
///Execute process
}
}main:
//setup dialog
//connect dialog button clicked to slot cancel
dialog->show();cancel slot:
//update bool exec to falseuser should be able to cancel the process by clicking the cancel button
This is not even pseudo-code...
How do you start the process, how do you try to stop it (or kill since stop can not work as there is no QProcess function for it). -
This is not even pseudo-code...
How do you start the process, how do you try to stop it (or kill since stop can not work as there is no QProcess function for it).Sorry, I did not explain it very well.
The question I have is I want to run a process in background and at the same time, I should be able to stop it from a dialog . Is it possible?I do not have a code because I am not sure how to do it. I was thinking in use a thread. Could you give me some details to implement it?
Thanks.
-
Sorry, I did not explain it very well.
The question I have is I want to run a process in background and at the same time, I should be able to stop it from a dialog . Is it possible?I do not have a code because I am not sure how to do it. I was thinking in use a thread. Could you give me some details to implement it?
Thanks.
@medihech
In the slots section ofQProcessyou havekill()andterminate(). What else are you looking for? And no need for any separate threads, won't help.When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.
Don't know what you're seeing. What signal, that for the click? Unless your computer is very busy running the other process so it doesn't service the request promptly. Start with a
qDebug()in your clicked handler so you know when it's called.Note that your
dialog->show()means it's (presumably) a modeless dialog (oh, actually your title says you have set it modal). You still have to allow the event loop to run. Can't tell from your code, but if yourwhile (bExec)blocks the event loop that might be a problem. Like I said, start by verifying how promptly you get the clicked signal.Ah, hang on:
cancel slot: //update bool exec to falseJust updating
bExecto exit thewhileloop is not enough to kill the spawned process. And I don't know what yourwhile (bExec)is looping on if you have spawned a sub-process. -
@medihech
In the slots section ofQProcessyou havekill()andterminate(). What else are you looking for? And no need for any separate threads, won't help.When I clicked the cancel button, It seems the signal is emited once the process is finished, but I want to be able to cancel the operation in the middle of the process.
Don't know what you're seeing. What signal, that for the click? Unless your computer is very busy running the other process so it doesn't service the request promptly. Start with a
qDebug()in your clicked handler so you know when it's called.Note that your
dialog->show()means it's (presumably) a modeless dialog (oh, actually your title says you have set it modal). You still have to allow the event loop to run. Can't tell from your code, but if yourwhile (bExec)blocks the event loop that might be a problem. Like I said, start by verifying how promptly you get the clicked signal.Ah, hang on:
cancel slot: //update bool exec to falseJust updating
bExecto exit thewhileloop is not enough to kill the spawned process. And I don't know what yourwhile (bExec)is looping on if you have spawned a sub-process. -
@JonB
Thanks, but I dont understand completely.I need to cancel the process and continue it from the dialog several time because it is a long process.
I could send a code it is necessary, but it did not work.@medihech said in Problem with a modal dialog connecting with a process:
I need to cancel the process and continue it from the dialog several time because it is a long process.
Did you try
kill()/terminate()? Did you verify when your clicked slot is getting called as I mentioned a couple of times? I don't know what there is not to understand, if you want to kill a process on a click then just do so. -
Sorry, I did not explain it very well.
The question I have is I want to run a process in background and at the same time, I should be able to stop it from a dialog . Is it possible?I do not have a code because I am not sure how to do it. I was thinking in use a thread. Could you give me some details to implement it?
Thanks.
@medihech said in Problem with a modal dialog connecting with a process:
. Is it possible?
Yes. See the documentation on how to start a process.