bug in kdevelop1.4's Qt2 MDI project template

Rüdiger Knörig ruediger at knoerig.de
Mon Jul 2 21:56:39 BST 2001


While working on a kdevelop Qt2 mdi project I got crashes if the loading of a 
document failed and a new document should be created. The code in the 
"openDocumentFile" member function of the doc object who should do this is:

  doc = new QtpLgviewerDoc();
  pDocList->append(doc);
  doc->newDocument();
  // Creates an untitled window if file is 0     
  if(!file)
  {
    untitledCount+=1;
    QString fileName=QString(tr("Untitled%1")).arg(untitledCount);
    doc->setPathName(fileName);
    doc->setTitle(fileName);
  }
  // Open the file
  else
  {
    try{doc->openDocument(file);}
    catch(QString errormsg)
    {
      QMessageBox::critical(this, tr("Error !"),tr(errormsg));
      delete doc;
      return;
    }
  }
  // create the window
  createClient(doc);

This causes trouble if the document could not be loaded (exception catch), so 
you have a destroyed object in pDocList!
To fix this, use the remove() method of pFocList:

  else
  {
    try{doc->openDocument(file);}
    catch(QString errormsg)
    {
      QMessageBox::critical(this, tr("Error !"),tr(errormsg));
      pDocList->remove(doc);
      return;
    }
  }

 The constructor of the app object sets AutoDelete to true, so the object ist 
 deleted.

-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list