Results 1 to 2 of 2

Thread: QDataSteam.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    38
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Question QDataSteam.

    I get the text from the UI's QTextEdit, and write to the file use QDataStrem,but if the input text has used Enter key, then I will get garbled from the file.

    There are some codes:
    Qt Code:
    1. QDataStream &operator<<(QDataStream &out,const MyClass &obj)
    2. {
    3. out << obj.m_name
    4. << obj.m_desc
    5. << obj.m_argMap
    6. << obj.resultVel
    7. << obj.m_code;
    8.  
    9. return out;
    10. }
    11.  
    12. QDataStream &operator>>(QDataStream &in, MyClass &obj)
    13. {
    14. in >> obj.m_name
    15. >> obj.m_desc
    16. >> obj.m_argMap
    17. >> obj.resultVel
    18. >> obj.m_code;
    19.  
    20. return in;
    21. }
    22.  
    23. .... WriteToFile()
    24. {
    25. .........................
    26. QFile file(path);
    27. if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
    28. return 1;
    29.  
    30. MyClass d;
    31. d.setName(name);
    32. d.setCode(code);
    33. d.setDescription(desc);
    34.  
    35. QDataStream out(&file);
    36. out.setVersion(QDataStream::Qt_4_6);
    37. out << d;
    38. file.close();
    39. .........................
    40.  
    41. }
    42.  
    43. .... ReadFromFile()
    44. {
    45. .........................
    46. QFile file(str);
    47. if (!file.open(QIODevice::ReadOnly))
    48. return 1;
    49.  
    50. MyClass d;
    51. QDataStream in(&file);
    52. in.setVersion(QDataStream::Qt_4_6);
    53. in >> d;
    54. file.close();
    55. .........................
    56.  
    57. }
    To copy to clipboard, switch view to plain text mode 

    What I get are like this : ㈀㌀㄀㈀㌀.........
    Last edited by wysota; 25th September 2010 at 07:48.

Similar Threads

  1. QDataSteam.
    By wookoon in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2010, 15:27

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.