Results 1 to 6 of 6

Thread: Progress bar Vs loop...

  1. #1
    Join Date
    Aug 2012
    Location
    Paris
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Progress bar Vs loop...

    Dear Sirs,

    I'm filling large Qtable with large data files, and I decided to add a progress bar.
    This works properly, however, I decided to add a 'Cancel' button, and things became more complicated.

    Indeed, during the data filling (for loops), the program is completely frozen, and no way to move windows, click on the Cancel button ....

    Would there be any solution which would help me ?

    Thanks a lot in advance,

    Best Regards,

    Stéphane

    Qt Code:
    1. // PROGRESS BAR -----------------------------------
    2.  
    3. // Main window
    4. QWidget *window_progress_bar = new QWidget;
    5.  
    6. // Progress bar + button
    7. QProgressBar *progressbar = new QProgressBar;
    8. QPushButton *button = new QPushButton ("Cancel");
    9.  
    10. // Layout
    11. QHBoxLayout *layout = new QHBoxLayout;
    12.  
    13. // Layout assignment
    14. layout->addWidget(progressbar);
    15. layout->addWidget(button);
    16.  
    17. // Set Layout
    18. window_progress_bar->setLayout(layout);
    19.  
    20. // Show the window
    21. window_progress_bar->show();
    22.  
    23. // ------------------------------------------------
    24.  
    25.  
    26. // Telemetry data importation and filling
    27. for (unsigned int i=0; i<data->get_row_nb(); i++)
    28. {
    29. for (unsigned int j=0; j<data->get_col_nb(); j++)
    30. {
    31. data->set_value(i, j, file_reader->get_data(i,j));
    32. QTableWidgetItem *newItem = new QTableWidgetItem( tr("%1").arg(data->get_value(i,j)) );
    33. // newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
    34. table_data->setItem(i, j, newItem);
    35. }
    36.  
    37. // Progress bar updating
    38. progressbar->setValue(100*(i+1)/(data->get_row_nb()));
    39. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    86
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Progress bar Vs loop...

    Maybe multitasking and QThreads?

  3. The following user says thank you to code_err for this useful post:

    Rakma74 (29th September 2012)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Progress bar Vs loop...

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Aug 2012
    Location
    Paris
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Progress bar Vs loop...

    Thanks code_err, this is exactely what I needed...


    In fact, even if I don't use the QProgressBar, the code is frozen during the 'for' loops...
    No particular problem with this in the past, but now, since I want to use a 'Cancel' button, things are different...

    Best Regards,

    Stéphane


    PS : Also, thanks to Wysota

  6. #5
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Progress bar Vs loop...

    If you want to keep your program resposive, then call qApp->processEvents(); inside the loop.

  7. The following user says thank you to boudie for this useful post:

    Rakma74 (1st October 2012)

  8. #6
    Join Date
    Aug 2012
    Location
    Paris
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Progress bar Vs loop...

    This is absolutely PERFECT !!

    Exactely what I needed... I tested it, it works perfectly and is so simple to implement...

    Thank you very much Boudie !!

Similar Threads

  1. How to use progress bar
    By bijay in forum Newbie
    Replies: 1
    Last Post: 28th March 2012, 10:44
  2. Replies: 4
    Last Post: 6th August 2011, 01:40
  3. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  4. Replies: 4
    Last Post: 11th March 2008, 11:44
  5. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 15:11

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.