Results 1 to 5 of 5

Thread: Unable to write to file QFile

  1. #1
    Join Date
    Jul 2009
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Unable to write to file QFile

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4. QFile file("testFile");
    5. if(!file.open(QIODevice::WriteOnly))
    6. qDebug()<<"Error opening the file";
    7. QTextStream streamToWrite(&file);
    8. const char* test = "Testing file write";
    9. streamToWrite<<test;
    10. file.close();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 15th July 2009 at 10:53. Reason: missing [code] tags

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Unable to write to file QFile

    so whats the problem?? can to explain more... is the file created?

  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unable to write to file QFile

    Are you Getting any error? The file is created or not? Try taking the content in a QString.

  4. #4
    Join Date
    Jul 2009
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Unable to write to file using QFile

    Quote Originally Posted by MrDeath View Post
    so whats the problem?? can to explain more... is the file created?

    File is created in directory where sources are present. I expected it to be in the directory of executable and I was wrong. Able to write the strings properly using QTextStream, wondering why using QDataStream writes some extra characters to File

  5. #5
    Join Date
    Dec 2007
    Posts
    627
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Unable to write to file using QFile

    Quote Originally Posted by cuter View Post
    File is created in directory where sources are present. I expected it to be in the directory of executable and I was wrong. Able to write the strings properly using QTextStream, wondering why using QDataStream writes some extra characters to File
    Because of encoding. QDataStream is used to write binary data, if your concern is only text better stuck with QTextStream.

Similar Threads

  1. How to write a QList into a binary file?
    By Lawand in forum Qt Programming
    Replies: 23
    Last Post: 15th June 2009, 10:04
  2. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24
  3. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  4. About File write operation
    By raghvendramisra in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2008, 11:41
  5. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.