Results 1 to 4 of 4

Thread: QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"

  1. #1
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"

    My Code:


    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QMessageBox>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication *app=new QApplication(argc, argv);
    7. QString localFileName="file.text";
    8. QFile *file=new QFile(localFileName);
    9. if(file->open(QIODevice::ReadWrite))
    10. {
    11. QMessageBox::information(0,"Error: Cannot open["+file->fileName()+"] "+file->errorString());
    12. return 0;
    13. }
    14. return app->exec();
    15. }
    To copy to clipboard, switch view to plain text mode 


    this will output:Error: Cannot open[file.text] Unknow error.

    ?????? why??

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"

    QFile:pen returns TRUE on success and false if it fails.
    So you're testing wrong there.
    Switch to:
    Qt Code:
    1. if(!file->open(QIODevice::ReadWrite))
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"

    Re-check the if-clause. QFile::open() returns true if successful; otherwise returns false.
    J-P Nurmi

  4. #4
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"

    OH!!!!!!!!!!!!!!!!!!!!!!!!! God!!!!

    is so low problem!!!!

    I'm a fool!~~~ thank you Sir~ thank you~~

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.