GUI gets hang while copying data from one file to another
I have GUI in which on button click copy the content from one file to another file.While copying my GUI get hangs and it get release once the copying is done.
I tried to implement QtConcurrent function in my program but still GUI hangs for couple of second.
My code
Code:
connect(ui->button1,SIGNAL(clicked()),this,SLOT(select_C_file()));
void MainWindow::select_C_file()
{
QDir directory
("Documents");
QString path
= directory.
filePath(" ");
QString fileName
= QFileDialog::getOpenFileName(this,tr
("Open File"),path,tr
("(*.lst)"));
//open the file path which has to copy
//Thread implementation
QFuture<void> future
= QtConcurrent
::run(this,
&MainWindow
::openCfile,
QString(fileName
));
future.waitForFinished();
void MainWindow
::openCfile(QString fileName
) {
//program to copy
}
}
My program is working perfectly but still my GUI is getting hang.
Please let me how can I use Qthread instead of QtConcurrent.Where my Qthread should start on the button click and should end once the copying is done or it should be in threadloop.
Re: GUI gets hang while copying data from one file to another
Quote:
Originally Posted by
anh5kor
I tried to implement QtConcurrent function in my program but still GUI hangs for couple of second.
Because you are calling waitForFinished()
Quote:
Originally Posted by
anh5kor
Please let me how can I use Qthread instead of QtConcurrent
You could first try not to block the main thread by not calling waitForFinished()
Cheers,
_
Re: GUI gets hang while copying data from one file to another
Re: GUI gets hang while copying data from one file to another
If you want to get notified when the future is completed, have a look at QFutureWatcher.
Cheers,
_