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. [SOLVED] App crash when last media has ended

[SOLVED] App crash when last media has ended

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 669 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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));
    }@

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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));
      }
      }@

      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