我在Qt应用程序中使用libSDL2。该代码在Linux和Windows下运行良好,但在Mac OS下失败。这是崩溃输出:
2015-05-12 10:24:35.598 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0
2015-05-12 10:24:35.643 testapp[4621:105425] An uncaught exception was raised
2015-05-12 10:24:35.643 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0
2015-05-12 10:24:35.643 testapp[4621:105425] (
0 CoreFoundation 0x00007fff9332764c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff967686de objc_exception_throw + 43
2 CoreFoundation 0x00007fff9332a6bd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff93271a84 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff932715f8 _CF_forwarding_prep_0 + 120
5 testapp 0x000000010446af59 Cocoa_CreateWindowFrom + 73
6 testapp 0x000000010445fe1d SDL_CreateWindowFrom_REAL + 205
7 testapp 0x000000010417c83c main + 380
8 testapp 0x000000010417c6b4 start + 52
9 ??? 0x0000000000000001 0x0 + 1
)
该示例代码重现崩溃。它再次在Linux和Windows下工作,但不在Mac OS下工作。
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
if (SDL_VideoInit(NULL) != 0) {
qCritical("SDL_VideoInit() error: %s", SDL_GetError());
return EXIT_FAILURE;
}
QWidget* qwidget = new QWidget();
SDL_Window* sdlWindow = SDL_CreateWindowFrom((void*) qwidget->winId());
if (sdlWindow == NULL) {
qCritical("SDL_CreateWindowFrom error: %s", SDL_GetError());
return EXIT_FAILURE;
}
return app.exec();
}