[SOLVED] App crash when last media has ended
-
Hello, I have Media Player and my problem is when last song ends, program crashes... I figured out which piece of code is doing a problems, but no idea how to fix it...
I have a highlight function which highlights current item and set previous item color to default... If I set playlist on Loop, then it won't crash but normally return back to the first item (start of playlist) and continue playing songs from the beginning... But if playlist is in normal mode - no repeats, then it will crash when a last song on the playlist ends... When last song ends playlist current index returns on the top of playlist and select 1st item (which is also played if I press "Play" button)... But highlight() for some reason does not follow it and crashes... Any idea how to solve it???
@connect(playlist, SIGNAL(currentIndexChanged(int)), this, SLOT(highlight()));@
@void MPlayer::highlight()
{
int count = ui->playlistWidget->count();
for(int i = 0; i < count; i++)
{
QListWidgetItem *item = ui->playlistWidget->item(i);
item->setBackgroundColor(QColor(255,255,255,0));}//These three lines below causing program to crash...
int index = playlist->currentIndex();
ui->playlistWidget->setCurrentItem(ui->playlistWidget->item(index));
ui->playlistWidget->currentItem()->setBackgroundColor(QColor(114, 151, 0));
}@ -
SOLVED!!!
@void MPlayer::highlight()
{
if(playlist->currentIndex() == -1)
{
ui->playlistWidget->setCurrentRow(playlist->currentIndex() != -1? playlist->currentIndex():0);
ui->playlistWidget->currentItem()->setBackgroundColor(QColor(114, 151, 0));
}
else
{
int count = ui->playlistWidget->count();
for(int i = 0; i < count; i++)
{
QListWidgetItem *item = ui->playlistWidget->item(i);
item->setBackgroundColor(QColor(255,255,255,0));}
int index = playlist->currentIndex();
ui->playlistWidget->setCurrentItem(ui->playlistWidget->item(index));
ui->playlistWidget->currentItem()->setBackgroundColor(QColor(114, 151, 0));
}
}@