Results 1 to 4 of 4

Thread: GUI gets hang while copying data from one file to another

  1. #1
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Question 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
    Qt Code:
    1. connect(ui->button1,SIGNAL(clicked()),this,SLOT(select_C_file()));
    2. void MainWindow::select_C_file()
    3. {
    4. QDir directory("Documents");
    5. QString path = directory.filePath(" ");
    6. QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"),path,tr("(*.lst)"));//open the file path which has to copy
    7.  
    8. //Thread implementation
    9. QFuture<void> future = QtConcurrent::run(this,&MainWindow::openCfile,QString(fileName));
    10. future.waitForFinished();
    11.  
    12. void MainWindow::openCfile(QString fileName)
    13. {
    14. //program to copy
    15. }
    16.  
    17. }
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GUI gets hang while copying data from one file to another

    Quote Originally Posted by anh5kor View Post
    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 View Post
    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,
    _

  3. #3
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Thumbs up Re: GUI gets hang while copying data from one file to another

    Thankyou its working

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. Replies: 3
    Last Post: 19th January 2016, 09:57
  2. QVector copying data with remove()
    By Momergil in forum Qt Programming
    Replies: 7
    Last Post: 13th June 2014, 18:50
  3. Copying data within model/widgetmapper
    By scott_hollen in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2011, 18:27
  4. memory leak when copying Qimage data
    By klobauster_toomc in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2010, 08:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.