PDA

View Full Version : Return-statement with no value



Stanfillirenfro
18th January 2014, 18:21
Hello!

I am facing a problem.
I want to use the conten of a file bt I have to check first if the file is opened.
I am receiving th efollowing error message: "return-statement with no value, in function returning 'QStringList"

My question: How to stop the process if the file can not be opened, since "return-statement does not work here?
break-statement can be used only in a loop.

Here is my code.



QStringList myWindow::open(QString &fileName)
{
QFile file(fileName);

if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this, "Warning", "Open a file please");
return;
}

// I do something here
}


Many thanks in advance.

anda_skoa
18th January 2014, 18:58
Your method has a return type of QStringList, so all exits from it must return a QStringList object.



return QStringList();


Cheers,
_

Stanfillirenfro
18th January 2014, 19:29
Many thanks!!!

I have gone the half of the way.

I have avoided willingly to indicate the path to the file after returning an empty QStringList, and the program crashes. Is there any way to ovoid this problem?

Many thanks in advance.

Added after 22 minutes:

Many thanks one more time. I can mark this subjet as resolved. The crashing problem was in the function calling the open() function.

Many thanks!