简体   繁体   中英

How do I get my QProgressDialog to show up when I don't know how long it will take?

I am using subprocess.call to run a command prompt command that takes a while (>5 minutes) to run:

subprocess.call([command, param1, param2], cwd=cwdDir)

I want to use a QProgressDialog to show that this command is running. I did this:

        progressDialog = QProgressDialog("Executing...", "", 0, 0)
        progressDialog.setCancelButton(None)
        progressBar = QProgressBar(progressDialog)
        progressBar.setMinimum(0)
        progressBar.setMaximum(0)
        progressDialog.setBar(progressBar)
        progressDialog.show()
        subprocess.call([command, param1, param2], cwd=cwdDir)
        progressDialog.close()

When I run my program, this is what shows up:

在此处输入图片说明

After a while, my commands finish executing and the window closes. How do I get it so that you can see the QProgressBar in the window?

You can use Qthread so program's event loop is not blocked. And increase the value of the progress bar either by a timer or read information from subprocess.call or just show the busy icon in the process bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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