Help with progressbar
-
I'm having trouble getting a progressbar to work in a dialog. It never triggers, doesn't move. However, I can take this code and plop it into mainwiindow.cpp and it works as expected.
Edit: if I click the mainwindow's titlebar then click the dialog's titlebar the bar moves a bit, but only when I do the clicks...???
ui->progressBar->setHidden(false); ui->progressBar->setValue(0); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(usbTimerEvent())); timer->start(2000); void usbfileDialog::usbTimerEvent() { int value = ui->progressBar->value() if (value >= 100) { value = 0; ui->progressBar->reset(); } ui->progressBar->setValue(value+1); }
-
@Jedd
I have tired your code. Seems there is no error in the provided code and its works. Where is the Dialog and how you implemented the Dialog in to Mainwindow ?
This is the code , I have tested.MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); mydialog = new QDialog(this); QHBoxLayout *mylayout = new QHBoxLayout(this); mylayout->addWidget(ui->progressBar); mydialog->setLayout(mylayout); mydialog->show(); ui->progressBar->setHidden(false); ui->progressBar->setValue(0); QTimer *timer = new QTimer(this); qDebug() << connect(timer, SIGNAL(timeout()), this, SLOT(valueChange())); timer->start(1000); } MainWindow::~MainWindow() { delete ui; } void MainWindow::valueChange() { int value = ui->progressBar->value(); if (value >= 100) { value = 0; ui->progressBar->reset(); } ui->progressBar->setValue(value+1); }
-
For me, the dialog is called via a button press
void MainWindow::on_fmButton_clicked() { fmdialog = new usbfileDialog(this); fmdialog->setModal(false); fmdialog->show(); }
The dialog code is below:
usbfileDialog::usbfileDialog(QWidget *parent) : QDialog(parent), ui(new Ui::usbfileDialog) { ui->setupUi(this); ui->usbprogressBar->setHidden(false); ui->usbprogressBar->setValue(0); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(usbTimerEvent())); timer->start(2000); } usbfileDialog::~usbfileDialog() { delete ui; }
-
I have attached the copy as you said. I did not see any problem like that. do you have any other widget in it ?
And by default
setModal is false
. you don't need to set to false andshow()
pops up the dialog as modeless.Edit:
may be , you need this
qApp->processEvents();
If it is busy in running some other local loop with out an event loop / busy in performing the long operation.