Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Data serialization
Forum Updated to NodeBB v4.3 + New Features

Data serialization

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shree_qt
    wrote on last edited by
    #1

    I want to write on file using textedit based on the concept of data serialization. What can I do?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      Hello @shree_qt

      Looks like you need to take a look at QDataStream class doc ,

      http://doc.qt.io/qt-4.8/qdatastream.html#details

      There is an example with explanation in this doc:

      Example (write binary data to a stream):

      QFile file("file.dat");
      file.open(QIODevice::WriteOnly);
      QDataStream out(&file);   // we will serialize the data into the file
      out << QString("the answer is");   // serialize a string
      out << (qint32)42;        // serialize an integer
      

      Example (read binary data from a stream):

      QFile file("file.dat");
      file.open(QIODevice::ReadOnly);
      QDataStream in(&file);    // read the data serialized from the file
      QString str;
      qint32 a;
      in >> str >> a;           // extract "the answer is" and 42
      

      Hope this can help !

      S 1 Reply Last reply
      5
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        In addition to previous post, You can look at http://www.ics.com/blog/object-serialization-and-persistence-using-qdatastream. It has nice example to do the same. If you need more help do let me know.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        Bharath_pthinksB 1 Reply Last reply
        5
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          This is a long-standing (6.5 years now) feature request, see https://bugreports.qt.io/browse/QTBUG-9258 but it would require a deep change in the underlying framework of QTextDocument.

          If you are interested only in writing you can use QTextDocumentWriter but there is no corresponding reader.

          You could implement a manual solution if you know what resources are used in the document

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • M mostefa

            Hello @shree_qt

            Looks like you need to take a look at QDataStream class doc ,

            http://doc.qt.io/qt-4.8/qdatastream.html#details

            There is an example with explanation in this doc:

            Example (write binary data to a stream):

            QFile file("file.dat");
            file.open(QIODevice::WriteOnly);
            QDataStream out(&file);   // we will serialize the data into the file
            out << QString("the answer is");   // serialize a string
            out << (qint32)42;        // serialize an integer
            

            Example (read binary data from a stream):

            QFile file("file.dat");
            file.open(QIODevice::ReadOnly);
            QDataStream in(&file);    // read the data serialized from the file
            QString str;
            qint32 a;
            in >> str >> a;           // extract "the answer is" and 42
            

            Hope this can help !

            S Offline
            S Offline
            shree_qt
            wrote on last edited by
            #5

            I am very beginning in qt and c++ also. Thanks for your post . I will try.

            1 Reply Last reply
            0
            • dheerendraD dheerendra

              In addition to previous post, You can look at http://www.ics.com/blog/object-serialization-and-persistence-using-qdatastream. It has nice example to do the same. If you need more help do let me know.

              Bharath_pthinksB Offline
              Bharath_pthinksB Offline
              Bharath_pthinks
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved