[Interest] Qt5: Converting from a QPixmap to an NSImage on OSX

Colin Dean cad at cad.cx
Mon Nov 5 17:25:39 CET 2012


On 11/03/2012 04:10 AM, Andreas Pakulat wrote:
> Hi,
> 
> On Sat, Nov 3, 2012 at 7:31 AM, Colin Dean <cad at cad.cx> wrote:
>> When I compile against Qt 5.0.0-beta2, it errors at the line marked above.
>> Looking through the Qt5 documentation, it appears that
>> QPixmap::toMacCGImageRef() no longer exists. I looked through the
>> documentation and verified its presence in Qt4 [1] and its absence in 5.0
>> [2].
>>
>>
>> As you can see, the code snippet here needs to take a QIcon and make it into
>> an NSImage. I can obviously transform the QIcon to a QPixmap, but I'm not
>> sure where to go from there. The QPixmap can be transformed to a QImage, but
>> there doesn't seem to be anywhere to go from there.
>>
>>
>> Is there another recommended way to accomplish this? Could these CGImageRef
>> methods have been erroneously removed? or perhaps simply moved to another
>> class?
> 
> The recommended way is apparently to wait for Qt 5.1 or to write your
> own conversion function, Qt5.0 has dropped most of the
> platform-specific API's and re-introduction is only planned as new
> modules in Qt5.1. This mailing lists archive should have some
> references to such cases.

Thanks for the information, Andreas. I searched around a little bit and
happened upon the thread "fromWinHICON missing from Qt 5" [1] that seems
to discuss the removal of the platform-specific methods I'm attempting
to use.

I looked through the Mac-specific implementation of of QPixmap [2] from
Qt 4.8. I started trying to copy things in to try to make it work, but I
quickly got into header hell trying to track down some of the things
necessary to get qt_mac_image_to_cgimage() to work!

I'm wary of trying to duplicate its functionality for only a temporary
thing, if such functionality shall return in Qt 5.1. Upgrading to Qt 5
was meant to be a fun little evening/weekend project - I don't think
it's productive to try to force things to work if they're technically
not ready to work yet.

Perhaps I'll revisit this when Qt 5.1 is out or someone wise in the ways
of Qt 5 on OSX can outline a solution.

[1]:
http://lists.qt-project.org/pipermail/interest/2012-September/003868.html
[2]: https://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/image/qpixmap_mac.cpp



More information about the Interest mailing list