Results 1 to 3 of 3

Thread: Detecting QIcon failed load from file

  1. #1
    Join Date
    Nov 2008
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Detecting QIcon failed load from file

    Hello.

    I am constructing QIcon and passing in a string file name.

    How do I detect if this has failed? It seems like if I deliberately construct it with garbage the icon is simply empty but I can't see anything in http://doc.qt.nokia.com/latest/qicon-members.html that describes success/failure of this load.

    Any ideas? (Other than asking QFile, it might be nice to know if the file was not an icon, for example)

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Detecting QIcon failed load from file

    You can ask isNull() to know if loading was successful.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Detecting QIcon failed load from file

    Whether that used to be true I don't know, but it doesn't currently work.
    The v5.1 documentation says:
    An icon is empty if it has neither a pixmap nor a filename.
    Note: Even a non-null icon might not be able to create valid pixmaps, eg. if the file does not exist or cannot be read.
    Likewise, with addFile() it says:
    Note: When you add a non-empty filename to a QIcon, the icon becomes non-null, even if the file doesn't exist or points to a corrupt file.
    Not the ideal solution, but this seems to work:
    Qt Code:
    1. icon.pixmap(QSize(64,64)).isNull()
    To copy to clipboard, switch view to plain text mode 

    It attempts to use the icon to retrieve or generate a pixmap of the size we're planning to use. It returns a null pixmap if the QIcon can't provide/generate such a image.

    Looking at the Qt sourcecode, I can't see any other way to detect the a failure.

Similar Threads

  1. HELP! QtLibrary.. Load library failed!!
    By Cantora in forum Newbie
    Replies: 1
    Last Post: 10th June 2009, 10:18
  2. Replies: 5
    Last Post: 29th April 2009, 22:39
  3. Deploying debug Qt application - failed to load ODBC driver
    By sureshbabu in forum Installation and Deployment
    Replies: 1
    Last Post: 1st November 2007, 12:35
  4. detecting that a file is currently being written to...
    By momesana in forum Qt Programming
    Replies: 11
    Last Post: 31st October 2007, 13:02
  5. Replies: 2
    Last Post: 31st May 2006, 21:52

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.