[Interest] Qt5: Converting from a QPixmap to an NSImage on OSX
cad at cad.cx
Sat Nov 3 07:31:16 CET 2012
Hello, I'm quite new to Qt development and my C++ and Obj-C skills are both long-time neophyte. Perfect conditions for learning, eh?
I'm trying to upgrade a project from Qt 4.x to 5.x. I've worked through some of the issues here and there, but I'm finding one that I can't seem to shake.
I have this method in a Obj-C class:
void MacDockIconHandler::setIcon(const QIcon &icon)
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
QSize size = icon.actualSize(QSize(128, 128));
QPixmap pixmap = icon.pixmap(size);
CGImageRef cgImage = pixmap.toMacCGImageRef();//compile errors here
image = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
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  and its absence in 5.0 .
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?
Any assistance welcome.
cad at cad.cx
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest