Results 1 to 4 of 4

Thread: It works once, but crashes if I do it again

  1. #1
    Join Date
    Mar 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default It works once, but crashes if I do it again

    I call this code on the startup of the application, but if I call it again, it crashes without any errors.

    Qt Code:
    1. void MCM::repopWList()
    2. {
    3. QDir mcDir = QDir(McFolder);
    4. QDir backupsDir = QDir(McFolder);
    5. mcDir.cd("saves");
    6. backupsDir.cd("MCM/backups");
    7. mcDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
    8. backupsDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
    9.  
    10. ui->worldList->clear();
    11.  
    12. //list the worlds
    13. QFileInfoList mcDirList = mcDir.entryInfoList();
    14. for (int i = 0; i < mcDirList.size(); i++) {
    15. QFileInfo fileInfo = mcDirList.at(i);
    16. ui->worldList->addItem(fileInfo.fileName());
    17. }
    18. QFileInfoList backupsDirList = backupsDir.entryInfoList();
    19. for (int i = 0; i < backupsDirList.size(); i++)
    20. {
    21. bool wExist = false;
    22. QFileInfo backupInfo = backupsDirList.at(i);
    23. for (int j = 0; j < ui->worldList->count(); j++)
    24. {
    25. string itemText = ui->worldList->item(j)->text().toStdString();
    26. if (itemText == backupInfo.fileName().toStdString())
    27. {
    28. wExist = true;
    29. }
    30. }
    31. if (wExist == false)
    32. {
    33. QString newWorld(backupInfo.fileName());
    34. ui->worldList->addItem(newWorld);
    35. }
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: It works once, but crashes if I do it again

    Have you run it in your debugger and looked at the backtrace you get when it crashes? What line causes the crash?

  3. #3
    Join Date
    Mar 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: It works once, but crashes if I do it again

    I get EXC_BAD_ACCESS

    caused by
    Qt Code:
    1. ui->worldList->clear()
    To copy to clipboard, switch view to plain text mode 

  4. #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: It works once, but crashes if I do it again

    Is ui->worldList a valid pointer? Have you deleted (or called deleteLater()) on the list at any time? Does any other part of your program hold a pointer to any QListWidgetItem in the list?

Similar Threads

  1. don't works on linux ?
    By 21did21 in forum Qwt
    Replies: 5
    Last Post: 5th September 2011, 10:28
  2. Replies: 3
    Last Post: 6th July 2011, 07:59
  3. QT 4.7.1 Win 7 x64 VS 2010: Debug works, Release crashes
    By new_voodoo in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2010, 20:14
  4. Replies: 1
    Last Post: 30th March 2009, 23:25
  5. How works tile() ?
    By looki in forum Qt Programming
    Replies: 0
    Last Post: 30th September 2008, 14:25

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.