I am trying to do some operation of the selected item in a list widget if a pushbutton is clicked. this is done using the following code
Qt Code:
  1. void Dialog::on_pushButton_clicked()
  2. {
  3. if(MyListWidget->currentItem()->isSelected())
  4. {
  5. MyListWidget->currentItem()->setText("YOU");
  6. QString my_text= MyListWidget->currentItem()->text();
  7. qDebug()<<my_text;
  8.  
  9. MyListWidget->currentItem()->setBackgroundColor(Qt::green);
  10. }
  11. else return;
  12. }
To copy to clipboard, switch view to plain text mode 
The program works well if we select an item before pressing the pushbutton,the problem occurs if no item is selected before clicking the button, the programme is crashed