Search code examples
c++qtqmediaplayerqprogressbar

QT: Connect QMediaPlayer to QProgressBar?


I want to connect the QProgressBar to the QMediaPlayer for Song Progress in QT5. How can i do that? Any help will be appreciated. Thanks.


Solution

  • Connect the QProgressBar to QMediaPlayer like this:

    connect(player, durationChanged(qint64), progressBar, setMaximum(int));
    connect(player, positionChanged(qint64), progressBar, setValue(int));
    

    You can also create a slot to normalize int64 to int.

    See: http://doc.qt.io/qt-5/qtwinextras-musicplayer-example.html