Question

everybody. I'm rewriting my qt4 music player in qt5. And i cant make an proper seek slider, like in phonon. Do you have an simple example of realization that part of UI?

UPD: here is my way to do that:

//mainwindow.cpp
connect(ui->seekSlider,SIGNAL(sliderMoved(int)),music,SLOT(setPosition(int)));
connect(music,SIGNAL(newPosition(qint64)),this,SLOT(positionChanged(qint64)));
connect(music,SIGNAL(newRange(qint64)),this,SLOT(durationChanged(qint64)));

void MainWindow::positionChanged(qint64 position)
{
    ui->seekSlider->setValue(position);
}

void MainWindow::durationChanged(qint64 duration)
{
   ui->seekSlider->setRange(0,duration);
}


//music class realization
player = new QMediaPlayer;
connect(player,SIGNAL(positionChanged(qint64)),this,SIGNAL(newPosition(qint64)));
connect(player,SIGNAL(durationChanged(qint64)),this,SIGNAL(newRange(qint64)));

void MusicControl::setPosition(int position)
{
    player->setPosition(position);
}

No correct solution

OTHER TIPS

I came across the same problem today, and I used the method introduced here: How to nicely "cast" qint64 to int for QProgressBar,

Regarding your solution, it probably works well most of the time, but since qint64 is 64-bit and int is mostly 32-bit, the value for the slider could be overflowed. Setting percentage values may be safer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top