PDA

View Full Version : File Reading (Seems Weird To Me)



Furkan
11th October 2010, 21:02
Hello.
I know how to read files but I discovered something weird the code below works fine.

QFile file(QApplication::applicationDirPath() + "/bilgi.txt");
if(!QFile::exists(QApplication::applicationDirPath () + "/bilgi.txt"))
{
QMessageBox::information(this, "asdasd", "not exists");
}
if(!file.open(QFile::ReadOnly))
{
QMessageBox::information(this, "asdasd", "readonly");
}
QByteArray data = file.readAll();
QTextCodec *codec = QTextCodec::codecForHtml(data);
QString string = codec->toUnicode(data);
QMessageBox::information(this, "asdasd", string);

But when I remove these codes below

if(!QFile::exists(QApplication::applicationDirPath () + "/bilgi.txt"))
{
QMessageBox::information(this, "asdasd", "not exists");
}
if(!file.open(QFile::ReadOnly))
{
QMessageBox::information(this, "asdasd", "readonly");
}

I can't read bilgi.txt file. I really wonder why it is like that.
Is there a really cool reason for that? or I don't know you tell me.

Timoteo
11th October 2010, 21:09
Weird, I replied once and it poofed. I hope I'm not double-posting lol.

Anyway, you removed the code that was opening the file.

Furkan
11th October 2010, 21:12
Oh my God!
I can't believe I overlooked it!
Thank you so much!