SDL_CreateWindowFrom() with Qt widget under Mac OS

六眼飞鱼酱① 提交于 2019-12-24 15:19:21

问题


I am using libSDL2 in a Qt app. The code is working well under Linux and Windows but is failing under Mac OS. Here is the crash output:

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
)

That sample code reproduce the crash. Again it is working under Linux and Windows but not under 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();
}

来源:https://stackoverflow.com/questions/30185781/sdl-createwindowfrom-with-qt-widget-under-mac-os

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!