问题
I am developing an application to Download file from NFS Server to my pc. To accomplish my task i wrote a Shell script to copy all the directories at given path and executing the script using QProcess. QProcess works fine and downloads all the directories.
Now, I want to show the downloading process report on QProgressBar. (same as we see on our windows while downloading files from internet).
I tried google search and find some idea using signal and tried as follow:
void NfsClient::NfsDownload()
{
download = new QProcess(this);
connect(download, SIGNAL(readyReadStandardOutput()), this, SLOT(displayProgressBar()) );
download->execute("bash /home/samurai/NfsFileDownload.sh");
}
void NfsClient::displayProgressBar()
{
ui->progressbar->setvalue(download->readAll().toInt());
}
But this readyReadStandardOutput() signal is never emitted. My Qt window becomes freeze while executing script. And Progressbar remains unchanged. :(
Is there any way to update the QProgressbar accordingly??? or any idea to show the GUI view of downloading process???
any suggestions/ideas ???
回答1:
I solved it by removing Shell script concept and implementing QDir class.
Since, to access NFS Server, Client has to mount server directory to one of its folder on it side. Thus in order to copy from a local folder its better to use inbuilt Qt class QDir for Copy, delete, upload functions.
来源:https://stackoverflow.com/questions/11752839/how-to-update-qprogressbar-while-executing-shell-script-in-qprocess