Problem with Timer in Media Player app

  • Hi,

    It is me again with my stupidity. When i finished my media player, with database of already played videos, i´ve got an idea, to add timer.

    I tried it 22 times, then i realised that i´ll need some help again.


    Here is my code when you can see that media player is working really well, but there is no timer. I´ve created QLabel as permanent widget, and QTimer which starts when program starts. But that is it, that is wrong. I need to start timer when i start a video, and when it ends, timer have to stop.

    Problem is that I am not able to connect timer, label which will show that time, and video/music that will be played.

    If there is someone who is willing to help me :)

    I would be really greatful.



  • @Qinyx Ahoj! What's the purpose of the timer?

  • Well, the purpose is that, when i start video i want from timer to show me on what minute video is, its full lenght etc. Something like this 00:00/15:53, you know, and it should be connected with that label which is going to show it right in the app.

  • @Qinyx But you don't need a timer for that, QMediaPlayer emits void positionChanged(qint64 position).

  • Oh, I see .. well i dont know if i would be able to complete it either, but i will try :) Thanks for now :)


  • Well as I said, i am too unexperienced in this, so was not able to connect it to that label that has to shows it.

  • Add another member function to your main window:
    void onPlayerPositionChanged(qint64 position); // in header

    void MainWindow::onPlayerPositionChanged(qint64 position)
       const auto text = QString("Position: %1 ms").arg(position);

    Then connect the player's signal to this function :-)

  • Hi there,

    i am sorry for late reply, i´ve had kynology competition. But i have been able to complete my project thanks to your help. I am really greatful.

    There is my code for comparasing:!ndwmxDgJ!LoX2SUHA2wIkSaFSXbQntA

    Thanks a lot again :)


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.