How to Update QprogressBar while executing Shell Script in QProcess?

有些话、适合烂在心里 提交于 2021-02-08 11:11:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!