Results 1 to 3 of 3

Thread: File Reading (Seems Weird To Me)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Question File Reading (Seems Weird To Me)

    Hello.
    I know how to read files but I discovered something weird the code below works fine.
    Qt Code:
    1. QFile file(QApplication::applicationDirPath() + "/bilgi.txt");
    2. if(!QFile::exists(QApplication::applicationDirPath() + "/bilgi.txt"))
    3. {
    4. QMessageBox::information(this, "asdasd", "not exists");
    5. }
    6. if(!file.open(QFile::ReadOnly))
    7. {
    8. QMessageBox::information(this, "asdasd", "readonly");
    9. }
    10. QByteArray data = file.readAll();
    11. QTextCodec *codec = QTextCodec::codecForHtml(data);
    12. QString string = codec->toUnicode(data);
    13. QMessageBox::information(this, "asdasd", string);
    To copy to clipboard, switch view to plain text mode 

    But when I remove these codes below
    Qt Code:
    1. if(!QFile::exists(QApplication::applicationDirPath() + "/bilgi.txt"))
    2. {
    3. QMessageBox::information(this, "asdasd", "not exists");
    4. }
    5. if(!file.open(QFile::ReadOnly))
    6. {
    7. QMessageBox::information(this, "asdasd", "readonly");
    8. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: File Reading (Seems Weird To Me)

    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: File Reading (Seems Weird To Me)

    Oh my God!
    I can't believe I overlooked it!
    Thank you so much!

Similar Threads

  1. Reading XML file using DOM
    By rk0747 in forum Qt Programming
    Replies: 6
    Last Post: 4th February 2010, 22:09
  2. reading a file
    By xaqt in forum Newbie
    Replies: 6
    Last Post: 14th September 2009, 15:04
  3. reading xml file
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2008, 02:01
  4. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55
  5. reading from a file
    By mickey in forum General Programming
    Replies: 32
    Last Post: 19th July 2007, 01:04

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
  •  
Qt is a trademark of The Qt Company.