SDL_CreateWindowFrom()使用Qt在Mac OS小部件(SDL_CreateWin

2019-10-23 02:26发布

我在一个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();
}
文章来源: SDL_CreateWindowFrom() with Qt widget under Mac OS