PDA

View Full Version : Show Dialog with Progresbar (Range(0,0)) while Process



mikrocat
25th November 2015, 08:42
createDialog();
...
Dialog->show();
startProcess();
...


void CreateDialog(){
Dialog = new QDialog(this);

QVBoxLayout *verticalLayout = new QVBoxLayout;
QLabel *DialogLabel = new QLabel;
QPushButton *stopButton = new QPushButton("Stop");
QProgressBar *DialogBar = new QProgressBar;

DialogBar->setRange(0,0);
DialogBar->setTextVisible(false);

connect(stopButton,SIGNAL(clicked()),this,SLOT(sto p()));

verticalLayout->addWidget(DialogLabel);
verticalLayout->addWidget(DialogBar);
verticalLayout->addWidget(stopButton);

Dialog->setWindowTitle(tr("Bitte Warten"));
DialogLabel->setText(tr("Starten Sie das Gerät neu. \nEs wird nach einem Gerät gesucht..."));

Dialog->setLayout(verticalLayout);
Dialog->window()->layout()->setSizeConstraint(QLayout::SetFixedSize);
Dialog->setModal(true);

Dialog->installEventFilter(this);

I have a Dialog which i show while I search for my Device (sending Data to port, if there is no answer: send again, if there is an answer: close the dialog, a button can interrupt the search).

While this Search I want the user to see the Progressbar so he knows that something is happening. It was working but then i changed the code and too late I realised that it isn't working anymore.

The progressbar is empty and does nothing, only when I click on the dialog and move it I can wake it up but then of course the process does not go on.
I would call QApplication::processEvents() to wake up the progressbar but I am not setting the value of the progressbar or anything like that, so i do not know where I should call it.

anda_skoa
25th November 2015, 12:35
How do you advance the progress bar value?
Does startProcess() block the thread?

Cheers,
_

P.S. there is QProgressDialog in case you haven't found it already

mikrocat
26th November 2015, 06:15
I do not advance the value of the progress. Just setrange(0,0) and it showed me continiously running progressbar once.

What do you mean by blocking the thread? Everything is working in one thread. I am able to click the button to interrupt the function, so I do not think that there is anything blocked.

anda_skoa
26th November 2015, 08:18
I do not advance the value of the progress. Just setrange(0,0) and it showed me continiously running progressbar once.

That's strange, i've always had to change the value, e.g. with a timer if the processing function doesn't know about the progress bar/dialog



What do you mean by blocking the thread? Everything is working in one thread. I am able to click the button to interrupt the function, so I do not think that there is anything blocked.
Right, being able to click the button is a good indicator that the thread is not blocked.

Cheers,
_