Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:33:16+00:00 2026-06-14T02:33:16+00:00

I’m trying to show a busy waiting bar when one function is executing, my

  • 0

I’m trying to show a busy waiting bar when one function is executing, my problem is it stop moving once the function starts.

MyProgressDialog *progBar= new MyProgressDialog();
    QProgressBar* bar = new QProgressBar(progBar);
    bar->setRange(0, 0);
    bar->setValue(0);

    progBar->setBar(bar);
    QString labeltext=QString("<qt> <center><big><b>%1</b></big></center> <br><b>%2</b><br> %3 <br><b>%4</b><br> %5</qt>")
                         .arg(progBar->labeltext)
                         .arg("File in :")
                         .arg(FileI)
                         .arg("File out :")
                         .arg(FileO);
    progBar->label->setText(labeltext);    
    progBar->setValue(10);
    progBar->show();
    progBar->setValue(20);
    Sleep(500);
    progBar->setValue(50);
    Sleep(500);
    MyFunction(FileI,FileO,mode,key);
    Sleep(500);
    progBar->setValue(80);
    Sleep(500);
    progBar->setValue(100);
    progBar->close();
    delete bar;
    delete progBar;

I warpped my function with a sleep and set value in purpose to let it moving but in vain, when I remove them MyProgressdialog didn’t show its contents, am I need to lunch my function in a separate thread ?
I tried to use QFutureWatcher:

 QFutureWatcher<void> futureWatcher;
                       QFuture<void> f1 = run(
                                              MyFunction,
                                              filePath,
                                              file.absolutePath()+"/OUT_"+fileN,
                                              1,
                                              key
                                              );
                       QObject::connect(&futureWatcher, SIGNAL(finished()), progBar, SLOT(reset()));
                       QObject::connect(progBar, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
                       QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), progBar, SLOT(setRange(int,int)));
                       QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), progBar, SLOT(setValue(int)));

                       // Start the computation.
                       futureWatcher.setFuture(f1);
                       // Display the dialog and start the event loop.
                       progBar->exec();
                       futureWatcher.waitForFinished();
                       delete progBar;

It works fine and my bar is moving when I call MyFunction just one time (for one file) but the problem occurs when I call MyFunction more than one time (for many files successively): it works but I get the same OUT_file for all files treated, I think it is multithreading issue.

EDIT: class MyProgressDialog

class MyProgressDialog: public QProgressDialog
{
  Q_OBJECT

  public:

    MyProgressDialog()
      {

      qDebug()<<"MyProgressDialog constructor";

      label=new QLabel(this);

      QPalette* palette = new QPalette();
      palette->setColor(QPalette::Window,"#F8F8FF");
      setPalette(*palette);

      QFont* font = new QFont("Courier New");
          font->setItalic(true);
          font->setPixelSize(15);
      setFont(*font);
      adjustSize();

     setWindowIcon(QIcon(QApplication::applicationDirPath()+"/icons/icon1.png"));
     setWindowFlags(Qt::WindowStaysOnTopHint);
     setMinimumWidth(500);
     setMinimumHeight(200);
     labeltext=QString("Please wait until Encryption/Decryption was done");
     label->setText(labeltext);
     label->adjustSize();
     label->setWordWrap (true);
     setLabel(label);

     setRange(0,100);
     setWindowTitle("MyFunction progress");        
     setModal(true);    

    }
    ~MyProgressDialog()
    {
        qDebug()<<"MyProgressDialog destructor";
        delete label;
    }



public:

  int value;     
  QString labeltext;
  QLabel* label;

};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:33:20+00:00Added an answer on June 14, 2026 at 2:33 am

    UI in Qt is event driven. So executing your code in same thread as ui will block every ui event untill your function is finished. There are two aproaches to show progress.

    1. Use thread for computing and send update events to UI
    2. Easier way: after each setValue and show calls call QApplication::processEvents(); static method. Calling QApplication::processEvents() will dispatch events currently queued on event loop. Those events include all ui related events

    Here is code sample for gcc/mingw gcc

    #include <QApplication>
    #include <QProgressBar>
    
    int main(int argc, char * argv[])
    {
        QApplication app(argc, argv);
    
        QProgressBar bar;
        bar.setRange(0, 100);
        bar.show();
        app.processEvents();
        usleep(250000);
    
        for(int i = 1; i <= 10; ++i)
        {
                bar.setValue(i * 10);
                app.processEvents();
                usleep(250000);
        }
    
        return 0;
    }
    

    It shows progress bar and steps it by 10 every 0,25s

    Your code should look something like this:

    MyProgressDialog *progBar= new MyProgressDialog();
    QProgressBar* bar = new QProgressBar(progBar);
    bar->setRange(0, 100); // note your "busy state won't be shown as you're changing value right after show
    bar->setValue(0);
    
    progBar->setBar(bar);
    QString labeltext=QString("<qt> <center><big><b>%1</b></big></center> <br><b>%2</b><br> %3 <br><b>%4</b><br> %5</qt>")
                         .arg(progBar->labeltext)
                         .arg("File in :")
                         .arg(FileI)
                         .arg("File out :")
                         .arg(FileO);
    progBar->label->setText(labeltext);    
    progBar->setValue(10);
    progBar->show();
    QApplication::processEvents(); // HERE
    progBar->setValue(20);
    QApplication::processEvents(); // HERE
    Sleep(500);
    progBar->setValue(50);
    QApplication::processEvents(); // HERE
    Sleep(500);
    MyFunction(FileI,FileO,mode,key);
    Sleep(500);
    progBar->setValue(80);
    QApplication::processEvents(); // HERE
    Sleep(500);
    progBar->setValue(100);
    progBar->close();
    QApplication::processEvents(); // HERE
    delete bar;
    delete progBar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm trying to select an H1 element which is the second-child in its group
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.