简体   繁体   English

从Qt应用程序调用命令提示符而不冻结?

[英]Calling command prompt from Qt application without freezing?

In my Qt GUI application, I am calling the command prompt through: 在我的Qt GUI应用程序中,我通过以下方式调用命令提示符:

system("lots.exe & of.exe && commands.exe");

It opens up the command prompt (like I want it to), but freezes the Qt GUI application until I close the command prompt. 它打开命令提示符(就像我想要的那样),但冻结Qt GUI应用程序,直到我关闭命令提示符。 Is there someway to prevent this? 有什么办法可以防止这种情况吗? I saw that there is a QProcess class, but can't get it to bring up the command prompt. 我看到有一个QProcess类,但无法启动它以显示命令提示符。

Any help would be greatly appreciated! 任何帮助将不胜感激!

QProcess is really the answer. QProcess真的是答案。 If you want to use something like system() you'll have to either put the call in another thread or use popen or something simmilar for your platforms. 如果你想使用像system()这样的东西,你必须将调用放在另一个线程中,或者使用popen或者simmilar用于你的平台。

QProcess does have the setReadChannel which you could use to display your own console window to show the output. QProcess确实有setReadChannel ,您可以使用它来显示您自己的控制台窗口以显示输出。

您只需将该系统调用放在一个单独的线程中即可。

If you do not need any of the output, the easiest way would be to use QProcess::startDetached(). 如果您不需要任何输出,最简单的方法是使用QProcess :: startDetached()。

http://doc.qt.io/archives/4.6/qprocess.html#startDetached http://doc.qt.io/archives/4.6/qprocess.html#startDetached

If you do need the output, QtConcurrent::run with a futurewatcher containing the output would be less overhead/work than deriving QThread. 如果确实需要输出,那么使用包含输出的futurewatcher的QtConcurrent :: run将比导出QThread更少开销/工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM