Results 1 to 4 of 4

Thread: File Handling!!!

  1. #1
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default File Handling!!!

    I cannot write to the file and read from it
    here is my code..

    write:

    Qt Code:
    1. QFile file("dd.txt");
    2. file.open(QIODevice::WriteOnly);
    3. QTextStream out(&file);
    4. out<<d;
    5. file.close();
    To copy to clipboard, switch view to plain text mode 


    read:

    Qt Code:
    1. QFile f("dd.txt");
    2. f.open(QIODevice::ReadOnly | QIODevice::Text);
    3. QTextStream stream(&f);
    4. l=stream.readLine();
    5. f.close();
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 26th January 2011 at 19:50. Reason: missing [code] tags

  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: File Handling!!!

    Please notice the [code] tags, and what returns open()? Or errorString()?

  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: File Handling!!!

    "cannot write to the file and read from it" is too ambigous. The file is not created? The file is empty? The file was written but you can't read?

    As already stated, please add error checking into your code and tell us exactly what happens.

  4. #4
    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 Handling!!!

    The program will attempt to create this file in its working directory. Often that is a non-writeable location (e.g. "C:\Program Files\Your Program" on Windows).

Similar Threads

  1. file handling
    By santakdalai90 in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2009, 20:50
  2. Bug in MDI handling
    By daren in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2009, 14:13
  3. large file handling
    By sakthi in forum Qt-based Software
    Replies: 1
    Last Post: 30th October 2008, 00:34
  4. Collision handling 101
    By Morea in forum Qt Programming
    Replies: 9
    Last Post: 25th November 2006, 20:17
  5. string handling
    By vijay anandh in forum Qt Programming
    Replies: 4
    Last Post: 5th May 2006, 09:15

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.