Results 1 to 3 of 3

Thread: Return-statement with no value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Return-statement with no value

    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.

    Qt Code:
    1. QStringList myWindow::open(QString &fileName)
    2. {
    3. QFile file(fileName);
    4.  
    5. if(!file.open(QIODevice::ReadOnly))
    6. {
    7. QMessageBox::critical(this, "Warning", "Open a file please");
    8. return;
    9. }
    10.  
    11. // I do something here
    12. }
    To copy to clipboard, switch view to plain text mode 

    Many thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Return-statement with no value

    Your method has a return type of QStringList, so all exits from it must return a QStringList object.

    Qt Code:
    1. return QStringList();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. IF-Statement problem
    By ayanda83 in forum Newbie
    Replies: 2
    Last Post: 18th November 2013, 08:02
  2. Replies: 1
    Last Post: 22nd August 2013, 16:49
  3. Replies: 1
    Last Post: 2nd January 2013, 09:48
  4. Strange behavior of return statement
    By Raadush in forum Qt Programming
    Replies: 8
    Last Post: 11th October 2012, 10:31
  5. How to get value from a query statement ?
    By hohoanganh205 in forum Newbie
    Replies: 3
    Last Post: 5th January 2012, 14:23

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.