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. Reading file
Forum Updated to NodeBB v4.3 + New Features

Reading file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 28.2k 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.
  • B Offline
    B Offline
    benjiii
    wrote on last edited by
    #1

    Hi
    I am trying to read a file using QFile.
    After file open how to read the file .

    I have one C program in which it reads the file for particular size.

    @read_bytes = read( fd, event_buf, sizeof(struct input_event)*EVENT_BUF_NUM); @

    How do I perform this in Qt

    Thanks

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Check the "official documentation of QFile":http://qt-project.org/doc/qt-4.8/qfile.html. There is an "example how to read file":http://qt-project.org/doc/qt-4.8/qfile.html#reading-files-directly.

      http://anavi.org/

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lycis
        wrote on last edited by
        #3

        With Qt you could use "QTextStream":http://qt-project.org/doc/qt-4.8/qtextstream.html and "QDataStream":http://qt-project.org/doc/qt-4.8/qdatastream.html to access files very easily.

        Some example code to show how to use "QFile":http://qt-project.org/doc/qt-4.8/qfile.html and QTextStream:

        @
        void readFileFunction()
        {
        QFile file("test.txt");

        if(!file.open(QIODevice::ReadOnly))
        {
            qDebug() << "error opening file: " << file.error();
            return;
        }
        
        QTextStream instream(&file);
        QString line = instream.readLine();
        
        qDebug() << "first line: " << line;
        file.close();
        return
        

        }
        @

        QDataStream works the same way but is used for accessing non-text data.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          benjiii
          wrote on last edited by
          #4

          Hi

          I need to read a block of data say @sizeof( struct A)*10@

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            [[Doc:QFile]] has a method seek() and and a method read() that takes a length parameter.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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