Solved Problem with process!
-
@lusijie
Try moving the code to another block. There is a signal qApp aboutToQuit() which will be called before quitting the application. Handle this signal and write the system("D:/myQt/prcsnew/release/shutdown.bat") in that slot.QObject :: connect( qApp, SIGNAL(aboutToQuit()),&mainwindow,SLOT(shutdown()));
void shutdown (){system("shutdown.bat")}
-
@JNBarchan This is the result that I drag shutdown.bat into cmd.exe .
this is the result that i press the key of enter.
I doubleclicked the .bat file,it just pop the window like this:
-
@lusijie
You are saying that:-
You have a
.bat
which only contains a single line ofshutdown -s -t 60
, nothing else, exactly that, let's be 100% clear, right? -
If you run it from that Command Prompt it works?
-
If you double-click the
.bat
from Windows Explorer, however, it does not behave the same?
Strange. Is your Command Prompt elevated? What if you right-click on the
.bat
file in Explorer and selectRun as administrator
instead?BTW, this "freezing": although it shouldn't work like that, it sounds a bit like the
shutdown.bat
'sshutdown
statement is invokingshutdown.bat
again, instead of the Windows commandshutdown.exe
. Try either renaming yourshutdown.bat
tomyshutdown.bat
, or edit itsshutdown -s -t 60
line to readshutdown.exe -s -t 60
. (I'm 99% sure this is your "freezing" problem.) -
-
@JNBarchan Thanks a lot!If I right-click on the .bat file in Explorer and select Run as administrator,it does work!I can sure that .bat only contains a single line of shutdown -s -t 60.
Thank you again.I fix the problem as you say.I change my .bat file
to shutdown.exe -s -t 60,it does work! I find that the name of file doesn't influence the result.I want to know why the code cmd.exe shutdown -s -t 60 doesn't work and how do you find it. -
@Tirupathi-Korla Thank you a lot.As you say ,I change code like this:
QObject :: connect( qApp, SIGNAL(aboutToQuit()),&mainwindow,SLOT(shutdown())); void shutdown (){system("shutdown -s -t 60")}
It works!Thank you!
-
So, in your environment, either you have to run
shutdown
as an Administrator, or there is some confusion over your use of the wordshutdown
when you don't specify eithershutdown.bat
orshutdown.exe
, to do with which found on thePATH
, at a guess. Make all your calls have either the explicit.bat
or.exe
as appropriate.If when you do run
shutdown.exe
successfully there is some kind of dialog thrown up asking for confirmation, maybe it's possible that it doesn't work right when run from inside an app with redirection as opposed to from a terminal/Explorer, I don't know. I doubt anyone else here will either. You'll need to do your own investigations. -
@Tirupathi-Korla It need to change like this:
void shutdown (){system("shutdown.exe -s -t 60")}
The application run normally like this.
-
void shutdown (){system("shutdown.exe -s -t 60")}
That's fine if you don't need to use your
shutdown.bat
to do something else/additional. I presumed that since you had chosen to write a.bat
file instead, you had a reason for that.... But if you're happy I'm happy :) -
@JNBarchan Thank you very much! I am a chinese.If you take a holiday in China Wuhan in the future,I hope to take you see the Yellow Crane Tower and The Yangtze River.I hope you have a chance to visit in China.Best wishes to you!This is my email:863872260@qq.com.
-
@lusijie
LOL :) Thank you, I will bear this in mind if & when I take a vacation to China. :) -
@JNBarchan Thanks a lot!Best wishes to you.