In my code I use a method getNumberOfP_ForAdd()
. This method opens a file and returns a XMLDocumentWrapper*.
XMLDocumentWrapper* Tab::getNumberOfP_ForAdd()
{
QString defaultName = GuiUtil::getLastPath();
QString fileName = QFileDialog::getOpenFileName(this, "Open " + displayName + " File",
defaultName, displayName + " Files (*." + fileSuffix + ")", 0, 0);
if (fileName.isNull() || fileName.isEmpty()) {
qDebug() << "Load" << displayName << "aborted.";
return NULL;
}
GuiUtil::setLastPath(fileName);
// Open file
XMLDocumentWrapper* inputDoc = XMLDocumentWrapper::readFromFile(fileName);
if (inputDoc == NULL) {
qDebug() << "Load" << displayName << "aborted.";
return NULL ;
}
return inputDoc;
}
When I try to read a file there are 2 things I check first: Wheather
(fileName.isNull() || fileName.isEmpty())
and
(inputDoc == NULL)
If these statements are true I do
return NULL;
Can I simply return a NULL-Ptr or would I run into problems in doing so? Do I have to free that pointer again?