简体   繁体   English

为什么执行QProcess后QProgressDialog没有更新?

[英]Why is a QProgressDialog doesn't get updated after executing a QProcess?

I am using a QProgressDialog to show the status of a long running operation, which includes a step of running an external executable. 我正在使用QProgressDialog来显示长时间运行的操作的状态,其中包括运行外部可执行文件的步骤。 I run the external executable using the QProcess::execute() method. 我使用QProcess :: execute()方法运行外部可执行文件。 QprogressDialog works fine updating the label text till it reaches the QProcess::execute() method, after which it doesn't update the state. QprogressDialog可以很好地更新标签文本,直到到达QProcess :: execute()方法,此后才不更新状态。

How to update the state after running the executable. 运行可执行文件后如何更新状态。

QProcess::execute() is a blocking method: it will block its calling thread until the spawned process will terminate. QProcess::execute()是一种阻塞方法:它将阻塞其调用线程,直到生成的进程终止为止。 It you call this method from the main thread, UI events will not be handled until the method will return. 如果您从主线程调用此方法,则在该方法返回之前不会处理UI事件。

To get around this you can create an instance of QProcess (rather than using its static methods) and then create a slot that continues the part of the operation that happens after the external process finishes running, and connect it to the QProcess::finished(int, QProcess::ExitStatus) signal. 为了解决这个问题,您可以创建一个QProcess实例(而不是使用其静态方法),然后创建一个插槽,该插槽继续外部进程完成运行之后发生的部分操作,并将其连接到QProcess::finished(int, QProcess::ExitStatus)信号。

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

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