Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Progressbar problem
Forum Updated to NodeBB v4.3 + New Features

Progressbar problem

Scheduled Pinned Locked Moved C++ Gurus
10 Posts 5 Posters 7.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    r.bhardwaj
    wrote on last edited by
    #1

    i m a beginner in Qt and i m trying to show process bar for my application's gui . i have written following code
    @
    void my_app::progress()
    {
    int val=1;
    while(process.state()!=0)
    {
    ui->progressBar->setValue(val++);
    }
    ui->progressBar->setValue(100);
    }@
    but progress bar is hanging at 98% . Can any one suggest me some solution .
    thank you !

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Please use "code wrapping":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 for your post.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jake007
        wrote on last edited by
        #3

        I would say, that process I loaded before it gets to 100. It depends on your processor speed. On some computers it would go over 100, and on some not even to 90.
        If you take a look at the documentation, state function return float values from 0.0 to 1.0.
        You can multiply that value times 100, and set it to progress bar.


        Code is poetry

        1 Reply Last reply
        0
        • R Offline
          R Offline
          r.bhardwaj
          wrote on last edited by
          #4

          according to documentation
          http://qt-project.org/doc/qt-4.8/qprocess.html#state
          QProcess::state() retruns only 3 value 0,1and 2 so till process is running QProcess::state() will return 2 and after execution it will go to QProcess::NotRunning (0) state,so it will retrun 0. Then it should come out of while loop. but that's not happening and programs hangs. why ? Any solution ?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jake007
            wrote on last edited by
            #5

            Sorry.
            I was looking the wrong function.
            Do you know approximately how long your program is running or how long does it take to complete given task?

            Otherwise, it'll be hard to create accurate progress bar.


            Code is poetry

            1 Reply Last reply
            0
            • R Offline
              R Offline
              r.bhardwaj
              wrote on last edited by
              #6

              my program is taking very less time(~1sec) to execute .But if so Then progress bar should end rapidly ? where is problem arising in the code ??

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jake007
                wrote on last edited by
                #7

                The problem is, because you are countig val++, while your program is running. So, if it would take something to process 5 minutes for example, val would get extremly high value

                If it takes less than a second, you can cheat a little and set it maualy to 100 when exits a loop. It will be hardly noticable if even will be.

                If you want accurate progress bar, you'll need some data from the program, or mesaure time in micro seconds etc.


                Code is poetry

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  veeraps
                  wrote on last edited by
                  #8

                  @
                  void my_app::progress()
                  {
                  int val=1;
                  while (process.state()!=0)
                  {
                  ui->progressBar->setValue(val++);
                  }
                  ui->progressBar->setValue(100);
                  }
                  @

                  From the code snippet, my understanding is that as long as the process state is 'QProcess::Starting' or 'QProcess::Running', progress bar value is incremented starting from 1. Having said that what process are you starting and how long will that run? Remember the while loop will run until process state is changed to 'QProcess::NotRunning' i.e., process is completed.

                  When is my_app::progress() called or how is it called?

                  Perhaps you can use some of the QProcess signals to change progress bar - appreciate you to look into the documents of QProcess signals.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    The main problem for this approach is, that you are using a busy loop. That means that you don't give the application the time to do the other relevant things, like processing input, drawing, etc. That in turn means that your progress bar will not be updated.

                    In your case, it seems you don't know how long your process will run for, as you're just blindly increasing the progress value. Why not just use the progress bar mode for that then? Just set min, max and value to 0, and your progress bar will automatically animate a busy animation.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      r.bhardwaj
                      wrote on last edited by
                      #10

                      thank sir for suggestion . i can use busy Progress bar but for the record i m invoking my_app::progress() using following signal/slot mechanism :
                      @
                      connect(&my_app,SIGNAL(started()),this,SLOT(progress()));
                      my_app.start(program,arguments);
                      @

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved