Results 1 to 5 of 5

Thread: The program has unexpectedly finished.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Location
    Paris
    Posts
    11
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The program has unexpectedly finished.

    If you click in the button and no items are selected, ui->treeWidget->currentItem() return NULL.
    And when the line ptr->isSelected() is executed, your program crash...
    You need to add robustness.

  2. The following user says thank you to Guiom for this useful post:

    smemamian (31st March 2013)

  3. #2
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The program has unexpectedly finished.

    is it true ? :-?
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3.  
    4.  
    5. for(int i=0 ; i<100 ;i++)
    6. {
    7. ui->progressBar->setValue(i);
    8. QThread::msleep(2);
    9. }
    10. if(ui->treeWidget->currentItem()->isSelected())
    11. {
    12. QTreeWidgetItem *ptr = ui->treeWidget->currentItem();
    13. ptr->setBackgroundColor(0,Qt::red);
    14. ptr->setBackgroundColor(1,Qt::red);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Apr 2012
    Location
    Paris
    Posts
    11
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The program has unexpectedly finished.

    Nop, rather:

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QTreeWidgetItem *ptr = ui->treeWidget->currentItem();
    4.  
    5. for(int i=0 ; i<100 ;i++)
    6. {
    7. ui->progressBar->setValue(i);
    8. QThread::msleep(2);
    9. }
    10. if(ptr && ptr->isSelected())
    11. {
    12. ptr->setBackgroundColor(0,Qt::red);
    13. ptr->setBackgroundColor(1,Qt::red);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    or use selectedItems().cout() ...

  5. The following user says thank you to Guiom for this useful post:

    smemamian (31st March 2013)

  6. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: The program has unexpectedly finished.

    Seems a rather pointless progress bar. Empty to full in 100 steps over 200 milliseconds... and then do the 'work' in fractions of a millisecond?

Similar Threads

  1. Replies: 2
    Last Post: 28th March 2013, 22:28
  2. Replies: 4
    Last Post: 17th September 2012, 15:23
  3. the program has unexpectedly finished
    By narlapavan in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2012, 09:04
  4. Replies: 6
    Last Post: 24th June 2012, 18:32
  5. Program has unexpectedly finished
    By Maluko_Da_Tola in forum Newbie
    Replies: 5
    Last Post: 1st December 2010, 09:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.