Results 1 to 3 of 3

Thread: QFile not readable

  1. #1
    Join Date
    May 2011
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default QFile not readable

    Hello out there,
    i am trying to read from a file that the user chooses via a QFileDialog, but after that the file is not readyble...

    Qt Code:
    1. file = new QFile(QFileDialog::getOpenFileName(....));
    2. if(file.isReadable() != true)
    3. {
    4. //This gets executed
    5. QMessageBox msg(QMessageBox::Information, "DEBUG", "File not readable", QMessageBox::Ok);
    6. msg.show();
    7. return;
    8. }
    To copy to clipboard, switch view to plain text mode 

    The interesting thing is, that the messagebox never really appears. But when I start the programm in the debugger i can see step by step that the code in the if condition gets executed and that the messgebox is not complete drawn (Just a empty MsgBox appears without text, just the "DEBUG" title).

    What is going wrong?

  2. #2
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile not readable

    Try:

    Qt Code:
    1. QString filename=QFileDialog::getOpenFileName(....);
    2. if(filename.isEmpty()) return;
    3. file = new QFile(filename);
    4. file->open(QIODevice::ReadOnly); // Use ReadWrite if you want to write on it...
    5. if(file.isReadable() != true)
    6. {
    7. //This gets executed
    8. QMessageBox msg(QMessageBox::Information, "DEBUG", "File not readable", QMessageBox::Ok);
    9. msg.show();
    10. return;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Here: QFile and QIODevice
    Hth.

  3. The following user says thank you to NullPointer for this useful post:

    seux (11th August 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFile not readable

    Of course you cannot see the message box:
    Qt Code:
    1. {
    2. QMessageBox msg(QMessageBox::Information, "DEBUG", "File not readable", QMessageBox::Ok);
    3. msg.show();
    4. return; // message box is destroyed here
    5. }
    To copy to clipboard, switch view to plain text mode 
    Message box is deleted immediately after creation, use "exec()" instead of "show()". Or try with static methods:
    Qt Code:
    1. {
    2. QMessageBox::information(this,"DEBUG", "File not readable"); // blocks until message box is closed
    3. return;
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. XML human readable string.
    By m.p in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2011, 13:24
  2. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  3. convert ampersand encoded HTML into something readable
    By tetsuoii in forum Qt Programming
    Replies: 5
    Last Post: 24th October 2010, 18:49
  4. Readable Xml with QXmlStreamWriter
    By jano_alex_es in forum Newbie
    Replies: 8
    Last Post: 26th August 2009, 11:53
  5. How to make QTimeEdit Box readable only
    By Krishnacins in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2006, 08:10

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.