Results 1 to 5 of 5

Thread: QFile readAll() problem..

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QFile readAll() problem..

    Hi,

    I wrote the following piece of code to read the file data;

    Qt Code:
    1. QFile* LoggerManager::getLogFile()
    2. {
    3. if(_logFile.exists() &&
    4. _logFile.isOpen() &&
    5. _logFile.isReadable() &&
    6. (_logFile.size() > 0))
    7. {
    8. return &_logFile;
    9. }
    10.  
    11. return NULL;
    12. }
    13.  
    14. LoggerManager::getInstance()->getLogFile()->readAll()
    To copy to clipboard, switch view to plain text mode 

    But it returns me 0 all the time although the file is loaded(about 200 KB)

    Any ideas?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: QFile readAll() problem..

    You have three conditions than have to be met. Obviously, the first step would be to see which one of them fails. The second step: thinking why would need all those.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QFile readAll() problem..

    Hi,

    I'm trying to validate my input as much as I can. That's why I put those controls over there.

    Besides, I can enter inside the if-loop. I suppose I'm missing something different.

    By the way, I couldn't enter onBytesWritten as well when I wrote;

    Qt Code:
    1. connect(&_logFile,
    2. SIGNAL(bytesWritten(qint64)),
    3. this,
    4. SLOT(onBytesWritten(qint64)));
    5.  
    6. _logFile.write(str.toStdString().c_str());
    To copy to clipboard, switch view to plain text mode 

    Morever, I could create and load the file. But I can connect it and read it's data.

  4. #4
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QFile readAll() problem..

    use QDataStream (for binary files) or QTextStream (for text files) for read content of your file.
    Hopes to help you
    Life is about making the right decisions and moving on.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QFile readAll() problem..

    In your first post you are checking for an open file that is not empty and is readable. In your last post that same file is the target of writing. How is that file opened? Have you determined which of the conditions is failing from your first post?

Similar Threads

  1. QTcpSocket->readAll() doesn't have anything to read!
    By naturalpsychic in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2012, 16:20
  2. QTcpSocket, problems with readall()
    By Leo_san in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2011, 23:31
  3. How to obtain a QI,age from QTcpSocket->readAll
    By gorka_sm in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2011, 08:50
  4. Problem with QFile
    By viciv919 in forum Newbie
    Replies: 5
    Last Post: 17th March 2010, 16:04
  5. QHTTP Readall() function
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 17th April 2007, 00:55

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.