I do not know at what level of API you are working. I am not sure that you can detect the problem after the fact. That is, if all you have is a context (possibly implicit, like the current thread) that could not connect to its capabilities.
I believe Qt uses Cocoa under the hood. I also assume that he created NSOpenGLContext and calls -setView: on it. You get this error with an invalid subtraction if the browser does not have a window device during this call.
One of the common ways is to postpone the setting of the contextual representation until -drawRect: appears on it, since at this moment you are sure that there is a window in the window and there is a device in the window. (Although this ignores the ability to force a -cacheDisplayInRect:toBitmapImageRep: outside the normal window display mechanism. For example, -cacheDisplayInRect:toBitmapImageRep: )
If you just want to know at the dial-up point -setView: whether it is safe or not, I think you can rely on checking the [[view window] windowNumber] . The docs for -windowNumber say:
If the window does not have a window device, the return value will be equal to or less than 0.
Another approach is to prevent the problem, not detect it. The strategy for this is to make sure that the window has been shown and drawn before calling -setView: You can force this by ordering it on the screen and invoking -display on it.
source share