PDA

View Full Version : QFile readAll() problem..



zgulser
22nd June 2012, 12:41
Hi,

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




QFile* LoggerManager::getLogFile()
{
if(_logFile.exists() &&
_logFile.isOpen() &&
_logFile.isReadable() &&
(_logFile.size() > 0))
{
return &_logFile;
}

return NULL;
}

LoggerManager::getInstance()->getLogFile()->readAll()


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

Any ideas?

mvuori
22nd June 2012, 12:59
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.

zgulser
22nd June 2012, 13:38
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;



connect(&_logFile,
SIGNAL(bytesWritten(qint64)),
this,
SLOT(onBytesWritten(qint64)));

_logFile.write(str.toStdString().c_str());


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

Ali Reza
22nd June 2012, 18:10
use QDataStream (for binary files) or QTextStream (for text files) for read content of your file.
Hopes to help you

ChrisW67
23rd June 2012, 01:11
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?