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. Put Video Timer without using Design
Forum Update on Monday, May 27th 2025

Put Video Timer without using Design

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 992 Views
  • 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.
  • A Offline
    A Offline
    adityatrikha08
    wrote on last edited by adityatrikha08
    #1

    I am playing a video in Qt, I have a text box to enter the URL, Buttons to start and stop video.

    I have not used the Design for any of above.

    Can I get help on how to insert a timer which starts and stops on pressing the start and stop button respectively

    jsulmJ 1 Reply Last reply
    0
    • A adityatrikha08

      I am playing a video in Qt, I have a text box to enter the URL, Buttons to start and stop video.

      I have not used the Design for any of above.

      Can I get help on how to insert a timer which starts and stops on pressing the start and stop button respectively

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @adityatrikha08 I don't know what you mean by "Design".
      To start stop a timer see http://doc.qt.io/qt-5/qtimer.html

       QTimer *timer = new QTimer(this);
       connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing()));
       timer->start();
      ...
      // Later when stop button is clicked
      timer->stop();
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      2
      • Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @jsulm I guess that by "Design" @adityatrikha08 means "Qt Designer"
        And I guess the idea is the opposite, the "timer" should start when the start button is pressed (the same button that starts video playing) and "timer" should stop when stop button is pressed.
        If I'm right, then @adityatrikha08 needs a stopwatch -> measure the elapsed time from start to stop. In that case please take a look at QElapsedTimer class

        QElapsedTimer *timer =  new ;
        connect(startButton, SIGNAL(clicked()), timer, SLOT(start()));
        connect(stoptButton, SIGNAL(clicked()), this, SLOT(reportElapsedTime()));
        
        void XX::reportElapsedTime()
        {
            qDebug() << "Elapsed time: " << timer.elapsed() << "milliseconds";
        }
        

        Spoiler alert: code not tested, just to show the idea

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        jsulmJ A 2 Replies Last reply
        2
        • Pablo J. RoginaP Pablo J. Rogina

          @jsulm I guess that by "Design" @adityatrikha08 means "Qt Designer"
          And I guess the idea is the opposite, the "timer" should start when the start button is pressed (the same button that starts video playing) and "timer" should stop when stop button is pressed.
          If I'm right, then @adityatrikha08 needs a stopwatch -> measure the elapsed time from start to stop. In that case please take a look at QElapsedTimer class

          QElapsedTimer *timer =  new ;
          connect(startButton, SIGNAL(clicked()), timer, SLOT(start()));
          connect(stoptButton, SIGNAL(clicked()), this, SLOT(reportElapsedTime()));
          
          void XX::reportElapsedTime()
          {
              qDebug() << "Elapsed time: " << timer.elapsed() << "milliseconds";
          }
          

          Spoiler alert: code not tested, just to show the idea

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Pablo-J.-Rogina said in Put Video Timer without using Design:

          And I guess the idea is the opposite, the "timer" should start when the start button is pressed (the same button that starts video playing) and "timer" should stop when stop button is pressed.

          That was actually my understanding.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @adityatrikha08 I don't know what you mean by "Design".
            To start stop a timer see http://doc.qt.io/qt-5/qtimer.html

             QTimer *timer = new QTimer(this);
             connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing()));
             timer->start();
            ...
            // Later when stop button is clicked
            timer->stop();
            
            A Offline
            A Offline
            adityatrikha08
            wrote on last edited by adityatrikha08
            #5

            @jsulm thanks so much Sir, I tried using this but it didn't work the way i intended it to.

            Regards

            1 Reply Last reply
            0
            • Pablo J. RoginaP Pablo J. Rogina

              @jsulm I guess that by "Design" @adityatrikha08 means "Qt Designer"
              And I guess the idea is the opposite, the "timer" should start when the start button is pressed (the same button that starts video playing) and "timer" should stop when stop button is pressed.
              If I'm right, then @adityatrikha08 needs a stopwatch -> measure the elapsed time from start to stop. In that case please take a look at QElapsedTimer class

              QElapsedTimer *timer =  new ;
              connect(startButton, SIGNAL(clicked()), timer, SLOT(start()));
              connect(stoptButton, SIGNAL(clicked()), this, SLOT(reportElapsedTime()));
              
              void XX::reportElapsedTime()
              {
                  qDebug() << "Elapsed time: " << timer.elapsed() << "milliseconds";
              }
              

              Spoiler alert: code not tested, just to show the idea

              A Offline
              A Offline
              adityatrikha08
              wrote on last edited by
              #6

              @Pablo-J.-Rogina Thanks so much Sir, actually that is what I meant.
              I am trying this method i.e. using the QElapsedTimer, I'll let you know if this works well.

              Regards

              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