Hey Everybody,

Allright my setting is like this:

I created a derived MVC program using C++ and QT on Visual Studio 2008, that sends multiple instructions to our ERP system through an external program...

On each command posted this way the user application needs to wait for a return string and react accordingly, this all happens in SQL with a continuos... query that takes place every 500 miliseconds with a timeout after x tries

Because of the large number of automation and lack of "communication" with the user I have included a "QProgressBar" in a dialog which gets updated as the functionality flows

The problem:

During these database queries while the application is waiting for a response my Progressbar animation is extremely laggy... the end aim is to convert to IPC and I believe this will solve it... but users have a tendency to want everything perfect (as you would all know)

Is there a way to either disable the animation in Win7 or a way to run the animation "outside the application scope" so it wont be influenced by the application database queries

Low priority but I cant really find references to this on google that are helpful

any specific coding required I will gladly provide but as you can imagine I wont be able to display the entire program...

Dani AI

Generated

Short answer: the progress-bar animation is stuttering because the GUI thread is being blocked while you wait for the ERP/database response. UI painting and the widget animation run on the Qt event loop, so any Sleep or long synchronous wait on the main thread stops repainting. already moved toward timers; that helps only if the status-check itself is fast and non‑blocking. 's timer idea is the right direction, but for truly blocking checks you should move the blocking work off the GUI thread.

Two safe, practical approaches:

  • Use a QTimer in the GUI thread to poll only when the event loop is free (good when the check is quick and non-blocking):
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &MyDialog::pollStatus);
timer->start(500);

void MyDialog::pollStatus() {
    if (quickStatusReady()) {
        timer->stop();
        progressBar->setValue(progressBar->maximum());
    } else {
        progressBar->setValue((progressBar->value()+1) % (progressBar->maximum()+1));
    }
}
  • Use a worker object on a QThread (recommended when the check/blocking call is synchronous). Do the blocking polling inside the worker, emit progress signals, and update the QProgressBar from the main thread via signals/slots. Important: open any QSqlDatabase or other thread-bound resources inside the worker thread — Qt SQL connections are not shareable across threads.
// Worker::doWork runs in the worker thread
for (int i=0; i<tries; ++i) {
    QString status = blockingDbCheck();        // run in worker thread
    emit progress(i);
    if (status == "done") break;
    QThread::msleep(500);
}
emit finished();

Extra tips and cautions: avoid calling QApplication::processEvents() as a long‑term fix (it causes reentrancy issues). Use progressBar->setRange(0,0) for an indeterminate busy look if you don't have percent info. Reduce UI update frequency if progress updates are very frequent (batch them). Also consider moving to an event/IPC-driven design instead of polling—this lowers load and removes the need for tight polling loops.

Recommended Answers

All 3 Replies

I believe I have traced the problem to a "Sleep(500)" call in the waiting between status check to the database... is there any alternative or way around this I can implement?

Please put some example code. May be you can use timer to control the progressbar animation independently.

Managed it with timers... thnx in any case :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.