QPixmap::toWinHICON() in Qt5

Long story short, here’s a workaround to a common gripe, missing QPixmap::toWinHICON() in Qt5.

#if QT_VERSION >= 0x050000
extern HICON qt_pixmapToWinHICON(const QPixmap &p);
#define qt_pixmapToWinHICON(p) p.toWinHICON()

HICON hIcon = qt_pixmapToWinHICON(QPixmap("test.png"));


  1. Get rid of some obsolete functions in QImage / QPixmap / QPixmapData
  2. QtGui: Bring back HBITMAP/HICON conversion functions

2 Responses to “QPixmap::toWinHICON() in Qt5”

  1. Olivier Goffart

    Is it not missing Q_GUI_EXPORT ?

  2. J-P Nurmi

    You’re the C++ wizard so you tell me. 🙂 I thought it wasn’t necessary for an external function declaration. This piece of code links fine with MSVC2010 at least, but I haven’t tried other compilers.

Leave a Reply