Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting QTimeLine and QProgressBar to work
Forum Updated to NodeBB v4.3 + New Features

Getting QTimeLine and QProgressBar to work

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.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.
  • G Offline
    G Offline
    graham1941
    wrote on last edited by
    #1

    I am trying to get a timeline and a progress bar to work. The relevant code snippet is as follows:

    @
    void dlg_player::play() /// Slot from button clicked signal
    }
    ...
    calcLen(plLen);
    ui->lbl_plen->setText(plLen);
    start();
    }

    void dlg_player::start()
    {
    ui->progressBar->setRange(0,100); /// ui from Qt designer.
    QTimeLine *timeLine = new QTimeLine(mSecs, this);
    timeLine->setFrameRange(0, 100);
    connect(timeLine, SIGNAL(frameChanged(int)),
    ui->progressBar,SLOT(setValue(int))); /// ui from Qt designer
    timeLine->start(); /// Is this required?
    }

    void dlg_player::calcLen(QString plLen) /// Calculates m Secs from a "(mm:ss)" string
    {
    if(plLen.contains('(')) plLen.remove('(');
    if(plLen.contains(')')) plLen.remove(')');
    playLen = plLen;
    mSecs = HMStoSecs(playlLen) * 1000;
    }
    @

    It compiles and the debugger shows all variables as correct. The program starts OK but the progress bar does nothing.

    Any help or advice would be greatly appreciated.
    Thank you.
    Graham

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      what is the start value of progress bar ? Definitely start is required.

      try setting bar->setValue(0)

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • G Offline
        G Offline
        graham1941
        wrote on last edited by
        #3

        Thank you for your prompt reply.
        I tried ui->progressBar->setValue(0); in my code.
        (It was already set to zero in designer properties, so was the max and min values)
        It did not work.
        Thank you again
        Regards
        G

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          What is mSecs value ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            graham1941
            wrote on last edited by
            #5

            Hi
            mSecs is a qint32 and can of course be set to anything from, lets say, zero to one hour in milliseconds = 0 to 3600000 (Unlikely to be this much).
            My test code is 8 min 30 sec = 510000 mSecs.
            Thanks again
            Regards
            G

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Wild thought. Can check whether your start method is called first ? Issue may exist there only. Can you put some debug statement and check inside the start method.

              I made this sample. See how this works.

              @Widget::Widget(QWidget *parent)
              : QWidget(parent)
              {
              QProgressBar *bar = new QProgressBar(this);
              bar->setRange(0,100);
              bar->setValue(0);
              QTimeLine *tim = new QTimeLine(5000,this);
              tim->setFrameRange(0,100);
              connect(tim,SIGNAL(frameChanged(int)),bar,SLOT(setValue(int)));
              tim->start();
              }

              @

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              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