Results 1 to 8 of 8

Thread: Read Text file using structure..

  1. #1
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Read Text file using structure..

    Hai

    how to read Text file using structure.

    Qt Code:
    1. struct commonDetails()
    2. {
    3. char *no=new char[6];
    4. char *name=new char[10];
    5. };
    6. commonDetails cn;
    7. QFile fileA(fileName);
    8. fileA.open(QIODevice::ReadWrite);
    9. QTextStream data(&fileA);
    10. data>>cn;
    To copy to clipboard, switch view to plain text mode 

    but it is not working...
    help please

    umulingu
    Banaglore

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Read Text file using structure..

    Quote Originally Posted by umulingu View Post
    Qt Code:
    1. struct commonDetails()
    2. {
    3. char *no=new char[6];
    4. char *name=new char[10];
    5. };
    To copy to clipboard, switch view to plain text mode 
    Is it possible ?

    You can use QDataStream.
    Last edited by yogeshgokul; 11th September 2009 at 08:38.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read Text file using structure..

    QDataStream won't work as well unless you provide proper operators for the structure and unless the files was written using QDataStream as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read Text file using structure..

    then how to do use structure?


    and how to read continuous 5 characters[including space] in a text file..

    Qt Code:
    1. QTextStream data(&fileA);
    2. char *runno=new char[5];
    3. data>>runno;
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read Text file using structure..

    You can always do it like this:
    Qt Code:
    1. QFile file(...);
    2. file.open(QFile::ReadOnly);
    3. QByteArray data = file.read(5);
    4. strcpy(structure.no, data.constData());
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Read Text file using structure..

    Qt Code:
    1. struct commonDetails()
    2. {
    3. char *no=new char[6];
    4. char *name=new char[10];
    5. };
    To copy to clipboard, switch view to plain text mode 

    WTF,,, is this a function or struct def? should i go back to school?

  7. #7
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read Text file using structure..

    hai


    thanks for reply

    but i didn't get.

  8. #8
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read Text file using structure..

    Quote Originally Posted by MrDeath View Post
    Qt Code:
    1. struct commonDetails()
    2. {
    3. char *no=new char[6];
    4. char *name=new char[10];
    5. };
    To copy to clipboard, switch view to plain text mode 

    WTF,,, is this a function or struct def? should i go back to school?
    thanks for ur reply

    But I didn't get...

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 02:20
  2. Replies: 8
    Last Post: 8th May 2012, 10:39
  3. Replies: 5
    Last Post: 27th May 2009, 13:49
  4. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 2nd June 2006, 00:14
  5. Replies: 13
    Last Post: 1st June 2006, 15:01

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.