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
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
}
}
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
}
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks