QEventDispatcherWin32 :: processEvents逻辑问题

时间:2018-06-27 13:46:49

标签: qt

当看到qt源代码(QEventDispatcherWin32 :: processEvents)时,我发现如下所示的Logical Issues.code,首先它在下一个if(haveMessage)写入if(!haveMessage),因此在if(...)和其他{...}将永远不会执行,我认为是对的吗?

代码为:

if (!haveMessage) {
    // no message - check for signalled objects
    for (int i = 0; i < (int)nCount; i++)
        pHandles[i] = d->winEventNotifierList.at(i)->handle();
    waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, 0, QS_ALLINPUT, MWMO_ALERTABLE);
    if ((haveMessage = (waitRet == WAIT_OBJECT_0 + nCount))) {
        // a new message has arrived, process it
        continue;
    }
}
if (haveMessage) {
#ifdef Q_OS_WINCE
    // WinCE doesn't support hooks at all, so we have to call this by hand :(
    (void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM)&msg);
#endif

    if (d->internalHwnd == msg.hwnd && msg.message ==   WM_QT_SENDPOSTEDEVENTS) {
        if (seenWM_QT_SENDPOSTEDEVENTS) {
            // when calling processEvents() "manually", we only want to send posted
            // events once
            needWM_QT_SENDPOSTEDEVENTS = true;
            continue;
        }
        seenWM_QT_SENDPOSTEDEVENTS = true;
    }
    else if (msg.message == WM_TIMER) {
        // avoid live-lock by keeping track of the timers we've already sent
        bool found = false;
        for (int i = 0; !found && i < processedTimers.count(); ++i) {
            const MSG processed = processedTimers.constData()[i];
            found = (processed.wParam == msg.wParam && processed.hwnd == msg.hwnd && processed.lParam == msg.lParam);
        }
        if (found)
            continue;
        processedTimers.append(msg);
    }
    else if (msg.message == WM_QUIT) {
        if (QCoreApplication::instance())
            QCoreApplication::instance()->quit();
        return false;
    }

    if (!filterEvent(&msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
else if (waitRet >= WAIT_OBJECT_0 && waitRet < WAIT_OBJECT_0 + nCount) {
    d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0));
}
else {
    // nothing todo so break
    break;
}

0 个答案:

没有答案