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. [SOLVED]Fread convert to qt
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Fread convert to qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.6k 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
    Salvatello
    wrote on 20 Oct 2014, 16:42 last edited by
    #1

    I have code in c:
    @
    FILE *f;
    _ENT rec; (_ENT is a my structur)
    fread (&rec,1,sizeof(rec),f)
    @

    how to convert code in code qt??

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on 20 Oct 2014, 18:48 last edited by
      #2

      Hey, ~Salvatello!

      I suppose, you should read some documentation about QFile and QTextStream. If I understand you correctly, the problem you want to solve is trivial and requires basic stream reading from the file.

      Good luck!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Salvatello
        wrote on 21 Oct 2014, 08:00 last edited by
        #3

        I have a struct:
        @typedef struct {
        unsigned short idrec;
        char dir;
        unsigned char flag;
        double x1,
        y1,
        x2,
        y2,
        cx,
        cy,
        raggio;
        } _ENT;@

        and FILE *f;
        _ENT rec;

        then i have:
        @fread (&rec,1,sizeof(rec),f);
        if (rec.idrec != AAAA)
        {
        printf("ERROR");
        }
        ....
        ...
        ...
        @

        how is this translated code in qt.
        How can I read from a file byte of a certain size and save them in the struct _ENT ????

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 21 Oct 2014, 11:35 last edited by
          #4

          see "QDataStream":http://qt-project.org/doc/qt-4.8/qdatastream.html#details
          this page should contain all you need.

          You could implement the data stream operators (<<) for your _ENT struct.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Salvatello
            wrote on 21 Oct 2014, 13:09 last edited by
            #5

            ho risolto così:
            @ QFile filefile(percorsoFile);
            filefile.open(QIODevice::ReadOnly);
            filefile.read((char*)&rec,sizeof(rec));
            qDebug()<<rec.idrec;
            qDebug()<<rec.dir;
            qDebug()<<rec.flag;
            qDebug()<<rec.x1;
            qDebug()<<rec.x2;
            qDebug()<<rec.y1;
            qDebug()<<rec.y2;
            qDebug()<<rec.cx;
            qDebug()<<rec.cy;
            qDebug()<<rec.raggio;
            filefile.close();@

            1 Reply Last reply
            0

            1/5

            20 Oct 2014, 16:42

            • Login

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