×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    62

    Fill struct using QFile

    I have struct contains following members:

    MyStruct
    {

    unsigned int x;
    float y;
    float z;

    unsigned short m;
    char ph_ n;
    char ph_ l;

    char ph_r;
    BYTE inf_id;
    BYTE index;
    BYTE len_;
    };

    I need to read data from my file and fill my struct like that
    MyStrucct* ms;

    ... Read(ms, size)
    Can I do that using QFile?

    any one can help me with example?

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Fill struct using QFile

    Have you looked at the reference? http://doc.qt.nokia.com/4.6-snapshot/qfile.html

    There are a few examples there.

    Remember that you have to check the inherited members by clicking on the link above the main listing of members in order to see some of the most important methods (such as read()).

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    62

    Re: Fill struct using QFile

    I saw this kink... but I need example about how to fill struct...read function not take void*

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Fill struct using QFile

    I'd suggest you learn how to cast pointers then.

  5. #5
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Fill struct using QFile

    Do you mean something like this?
    Code:
    QFile file("file.bin");
    if (!file.open(QIODevice::ReadOnly))
      return;
    
    MyStrucct ms;
    file.read((char*)&ms, sizeof(ms));
    file.close();

  6. #6
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Fill struct using QFile

    Something like that.

Similar Threads

  1. QFile problem
    By BalajiR in forum Qt
    Replies: 9
    Last Post: 2010-03-04, 05:49
  2. QFile::seek: IODevice is not open
    By rongyihit in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 0
    Last Post: 2009-08-18, 09:33

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •