Results 1 to 15 of 15

Thread: file.open error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file.open error

    ->FullPath() puts the location and filename together to go into filename in the first block. But, it doesn't seem to matter if I do fielname = "C:/test/flag1.gam" or filename = it->FullPath() it still gives the same error returned by file.errorstring, it also doesnt seem to matter if the application is loaded onto my usb drive (H) or on the primary drive C

    As I said though, when I do filename = filelist.txt then file.open etc during the load function there are no errors. It only happens during the backup function (I haven't written the restore function yet). I think i'm going to create a new app w/o the load() function and just have the files as const strings and see if that changes anything.. probably not but who knows... it's really driving me nuts how it works once but not again or once and then only for the last file from the list...

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: file.open error

    No ideas why file.open would fail to open a file? Has no one encountered a problem like this before?
    People have plenty of ideas and have expressed them in this thread. Here is a summary of the usual suspects:

    QFile::open() will fail to open a file for reading because;
    • the file does not exist (often because you are using a relative file name and assuming the current working directory is what you think it is), or
    • because you have no rights to open the file.

    QFile::open() will fail to open a file for writing because;
    • you have no rights to write in the location specified,
    • a file already exists there but is read-only,
    • the location specified makes no sense (i.e. trying to save to /foo/bar when /foo does not exist).


    You have more-or-less refused to consider the possibility that your code is feeding dud file names QFile through whatever it is that "it" points at. There's not much more we can add.

  3. #3
    Join Date
    Feb 2010
    Posts
    18
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: file.open error

    Quote Originally Posted by pheonixstorm View Post
    ->FullPath() puts the location and filename together to go into filename in the first block. But, it doesn't seem to matter if I do fielname = "C:/test/flag1.gam" or filename = it->FullPath() it still gives the same error returned by file.errorstring, it also doesnt seem to matter if the application is loaded onto my usb drive (H) or on the primary drive C
    And you tested all possibilities for the path as constant String?(like c:\test\flag1.gam and c:\\test\\flag1.gam ...)

    Quote Originally Posted by pheonixstorm View Post
    it's really driving me nuts how it works once but not again or once and then only for the last file from the list...
    That sounds extremely as if there are some cr/lf characters in the filename as considered by mvuori. First the last line worked, because there was no linebreak after the last line and now there is one.

  4. #4
    Join Date
    Jan 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file.open error

    Quote Originally Posted by ChrisW67 View Post
    People have plenty of ideas and have expressed them in this thread. Here is a summary of the usual suspects:

    QFile:pen() will fail to open a file for reading because;
    • the file does not exist (often because you are using a relative file name and assuming the current working directory is what you think it is), or
    • because you have no rights to open the file.

    QFile:pen() will fail to open a file for writing because;
    • you have no rights to write in the location specified,
    • a file already exists there but is read-only,
    • the location specified makes no sense (i.e. trying to save to /foo/bar when /foo does not exist).
    This is actually the problem, though it isn't as clear cut as you would think. I have tried both relative and absolute path but neither work... As I stated in a post above (toward the beginning i think) no path I have tried has worked weather its using \ \\ / or //
    You have more-or-less refused to consider the possibility that your code is feeding dud file names QFile through whatever it is that "it" points at. There's not much more we can add.
    And I have stated also that I have tried both via filelist.txt as well as directly naming the file. Neither works. At this point i'm beginning to wonder if something may have been corrupted in the OS or my installation of QT.

    Quote Originally Posted by majorwoody View Post
    And you tested all possibilities for the path as constant String?(like c:\test\flag1.gam and c:\\test\\flag1.gam ...)

    That sounds extremely as if there are some cr/lf characters in the filename as considered by mvuori. First the last line worked, because there was no linebreak after the last line and now there is one.
    Yes, i've tried it all and no its not pulling in linefeeds or if it is they are not the problem as I can do filename = "flag1.gam" and still get the same problem.

    As soon as I encountered the problem I setup multiple QMessagebox in the code to show what was about to happen with both sections of file.open. In every one the messagebox spit out exactly what it should have yet I still got that frustrating error message. Ive even tried to find anything related to UAC (user access control) to see if that could be a cause but have yet to find anything even remotely close.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: file.open error

    Build this:
    Qt Code:
    1. #include <QtCore>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. QFile in("C:/windows/system32/user32.dll");
    9. QFile out(QDir::tempPath() + "/user32.dll");
    10. if (in.open(QIODevice::ReadOnly)) {
    11. if (out.open(QIODevice::WriteOnly)) {
    12. QByteArray data = in.readAll();
    13. qint64 written = out.write(data);
    14. qDebug() << "Read:" << in.size() << "Wrote:" << written;
    15. out.close();
    16. }
    17. else {
    18. qDebug() << "Cannot open output file" << out.errorString();
    19. }
    20. }
    21. else {
    22. qDebug() << "Cannot open input file" << in.errorString();
    23. }
    24. return 0;
    25. }
    To copy to clipboard, switch view to plain text mode 

    Run it. Tell us which bit doesn't work.

Similar Threads

  1. fatal error LNK1104: cannot open file 'libgles_cm.lib
    By danmaliki in forum Installation and Deployment
    Replies: 2
    Last Post: 24th March 2011, 13:17
  2. Replies: 3
    Last Post: 1st November 2010, 16:33
  3. Replies: 0
    Last Post: 3rd June 2010, 04:54
  4. Replies: 4
    Last Post: 9th May 2010, 16:18
  5. Qt 4.1.4 on VS2005 error- cannot open input file 'qtmain.lib'
    By Ashish in forum Installation and Deployment
    Replies: 10
    Last Post: 11th October 2006, 16:05

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.