Results 1 to 3 of 3

Thread: QFile write isn't stable

  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFile write isn't stable

    Hi all!

    I have a client-server application and the network settings are loaded from a txt file that can be overwritten by the administrator but I am have some problems writing the textstream to the file.

    the txt file looks like this:

    192.168.1.220
    11001
    this is the function to write:

    Qt Code:
    1. QFile file("/opt/esp/Client/Settings/CL_settings.txt");
    2. if (!file.open(QIODevice::WriteOnly))
    3. return;
    4.  
    5. QTextStream out(&file);
    6. out << ui.lineEdit_16->text() << "\n" << ui.lineEdit_17->text() << endl;
    To copy to clipboard, switch view to plain text mode 

    the open and reading part works perfectly but when I write with that function, sometime it writes the first line and then the second, other times writes a blank line in the middle, then 2 blank lines, and maybe then back to normal...

    I tried other ways:

    Qt Code:
    1. out << ui.lineEdit_16->text() << "\n" << ui.lineEdit_17->text();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. out << ui.lineEdit_16->text() << "\n"
    2. out << ui.lineEdit_17->text();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. out << ui.lineEdit_16->text();
    2. out << ui.lineEdit_17->text();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. out << ui.lineEdit_16->text() + out << ui.lineEdit_17->text();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. out << ui.lineEdit_16->text() << "\n"
    2. << ui.lineEdit_16->text();
    To copy to clipboard, switch view to plain text mode 

    they all give me the same problem and my co-worker has a program that does the same thing and it works well for him.

    thanks in advance

  2. #2
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile write isn't stable

    Where is the text in your line edits coming from and how is it being set?
    Got to keep the loonies on the path ...

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile write isn't stable

    Maybe more than one instance of the application (or some other application) tries to write to the same file at the same time? Also you don't seem to be truncating the file so you overwrite old contents but if new contents is shorter than the old then the part that is not overwritten will still be in the file (so if your file was 20 bytes long and you open it for writing and write 10 bytes, it will still be 20 bytes long).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    ruben.rodrigues (16th July 2010)

Similar Threads

  1. QFile write and file modyfication time
    By Talei in forum Newbie
    Replies: 1
    Last Post: 9th May 2010, 20:46
  2. QFile - QDataStream read and write each character
    By nhs_0702 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2010, 19:03
  3. possible open/write two files same time with QFile
    By npotency in forum Qt Programming
    Replies: 4
    Last Post: 15th November 2009, 00:28
  4. Unable to write to file QFile
    By cuter in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2009, 11:19
  5. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 14:12

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.