Results 1 to 10 of 10

Thread: Problem in writing to a file

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Problem in writing to a file

    Hello! i am new to Qt and i have a problem in writing to a file.

    when i specify ReadOnly, it seems to be fine. it can open and read the contents of the file. but if i write WriteOnly or ReadWrite, it cannot even open the file. Why is that so?

    hope you can help me on this. BTW, i got the code from the Qt documentation.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem in writing to a file

    Obviously you don't have the write permission for the file.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in writing to a file

    Or perhaps even the directory. If you are writing on Windows 7 for example, directories such as Program Files are read only unless you request permission from the user via UAC.

  4. The following user says thank you to squidge for this useful post:

    darlene (1st May 2011)

  5. #4
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problem in writing to a file

    Thanks for your reply.

    it is just a text file i added as a resource file. Can we not write on resource files?

    my code looks like this

    Qt Code:
    1. QFile file(":/files/fav.txt");
    2. if (!file.open(QIODevice::ReadWrite | QIODevice::Text)){
    3. qDebug("file not opened");
    4. qDebug(file.errorString().toStdString().c_str());
    5. return;
    6. }
    To copy to clipboard, switch view to plain text mode 

    and the output of the errorString is "Unknown error".
    Last edited by darlene; 1st May 2011 at 06:40.

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in writing to a file

    Resources are part of your applications executable. If you were to write to them it would destroy the applications integrity, therefore writing is not allowed.

  7. The following user says thank you to squidge for this useful post:

    darlene (17th May 2011)

  8. #6
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problem in writing to a file

    hello. thank you very much..

    if that is the case, how do i save a file (like a .json file) that will be downloaded from the internet to be used by my mobile app?

    where are those files saved?

  9. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in writing to a file

    That depends on whether you need to store it after your application has exited or not. Most mobile apps have access to at least some NV storage.

  10. #8
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problem in writing to a file

    I see.

    Yes, the file is going to be used by the app so it needs to be saved. The problem is i have no idea where should it be saved.

    i really have no idea on this. Thank you very much for the reply.

  11. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in writing to a file

    You shouldn't need to specify a location as the default is typically your private storage area.

  12. #10
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Problem in writing to a file


Similar Threads

  1. writing to a file the \ thingie
    By afflictedd2 in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2008, 00:18
  2. problem writing an xml file
    By mickey in forum General Programming
    Replies: 1
    Last Post: 28th January 2008, 16:05
  3. Writing a XML file
    By Djony in forum Qt Programming
    Replies: 7
    Last Post: 5th February 2007, 16:23
  4. XML file writing
    By mbjerkne in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 19:04
  5. Writing an XML file
    By qball2k5 in forum Qt Programming
    Replies: 9
    Last Post: 19th March 2006, 10:58

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.