Results 1 to 4 of 4

Thread: How to read text only as it is from file

  1. #1
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question How to read text only as it is from file

    hi all
    i am working on mac OSX and using QT 4.1
    firstly i am selecting a file , from QFileDialog ::getOpenFileName, to read
    i am getting the whole text data in String but not as same as it is in File
    like if in a file i have spaces an freeline(line without characters),or if data is in next line then it show in next line
    but in my case its not happening same....

    so now i want to get the data as it is ,as it is in file (which is selected from QFileDialog:: getOpenFileName).

    waiting for your co-ordination

    TIA

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to read text only as it is from file

    How do you exactly read the data?

    Try using setTextModeEnabled(true) and using QFile::readAll. It returns a QByteArray, from which you can build a QString.
    Anyway, reading an entire file in a single pass is not a good idea, since it can be pretty big.

    If it still doesn't work,. then post some code.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to read text only as it is from file

    Or use a QTextStream on the file and use readAll. It returns a QString.

    Regards

  4. The following user says thank you to marcel for this useful post:

    thomasjoy (9th August 2007)

  5. #4
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question Re: How to read text only as it is from file

    now, tell me i have a buffer of data that has been read
    tell how i can set that data in treeWidget's coloumn which is in buffer
    and buffer is of const char * type....
    do tell me is there any direct way or indirect way(using any diffrent metthod like getting each byte and setting to desired location)...


    to read the data i had used the basic c operation fopen,fread...

    TIA

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 01:20
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  4. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 1st June 2006, 23:14
  5. Replies: 13
    Last Post: 1st June 2006, 14: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.