Rakma74
28th September 2012, 20:02
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
// PROGRESS BAR -----------------------------------
// Main window
QWidget *window_progress_bar = new QWidget;
// Progress bar + button
QProgressBar *progressbar = new QProgressBar;
QPushButton *button = new QPushButton ("Cancel");
// Layout
QHBoxLayout *layout = new QHBoxLayout;
// Layout assignment
layout->addWidget(progressbar);
layout->addWidget(button);
// Set Layout
window_progress_bar->setLayout(layout);
// Show the window
window_progress_bar->show();
// ------------------------------------------------
// Telemetry data importation and filling
for (unsigned int i=0; i<data->get_row_nb(); i++)
{
for (unsigned int j=0; j<data->get_col_nb(); j++)
{
data->set_value(i, j, file_reader->get_data(i,j));
QTableWidgetItem *newItem = new QTableWidgetItem( tr("%1").arg(data->get_value(i,j)) );
// newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
table_data->setItem(i, j, newItem);
}
// Progress bar updating
progressbar->setValue(100*(i+1)/(data->get_row_nb()));
}
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
// PROGRESS BAR -----------------------------------
// Main window
QWidget *window_progress_bar = new QWidget;
// Progress bar + button
QProgressBar *progressbar = new QProgressBar;
QPushButton *button = new QPushButton ("Cancel");
// Layout
QHBoxLayout *layout = new QHBoxLayout;
// Layout assignment
layout->addWidget(progressbar);
layout->addWidget(button);
// Set Layout
window_progress_bar->setLayout(layout);
// Show the window
window_progress_bar->show();
// ------------------------------------------------
// Telemetry data importation and filling
for (unsigned int i=0; i<data->get_row_nb(); i++)
{
for (unsigned int j=0; j<data->get_col_nb(); j++)
{
data->set_value(i, j, file_reader->get_data(i,j));
QTableWidgetItem *newItem = new QTableWidgetItem( tr("%1").arg(data->get_value(i,j)) );
// newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
table_data->setItem(i, j, newItem);
}
// Progress bar updating
progressbar->setValue(100*(i+1)/(data->get_row_nb()));
}