qt nativeEvent cannot receive USB’s insertion message QT DBTDEVICEARIVAL

2023-03-18  

Re -load the NativeEvent method in QwidGT, but cannot receive DBT_DEVICEARIVAL and DBT_DEVICEREMOVECOMPLETE messages

    MSG* msg = reinterpret_cast<MSG*>(pMessage);
    auto wParam = msg->wParam;
    if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {

        auto lParam = msg->lParam;
        auto deviceType = reinterpret_cast<DEV_BROADCAST_HDR *>(lParam)->dbch_devicetype;
        if (deviceType == DBT_DEVTYP_VOLUME) {

            auto unitmask = reinterpret_cast<DEV_BROADCAST_VOLUME *>(lParam)->dbcv_unitmask;
            for (int i = 0; i < 32; ++i) {

                if ((unitmask & (1 << i)) != 0) {

                    // setDriveChanged(‘A’ + i, wParam == DBT_DEVICEARRIVAL);
                }
            }
        }
    }
    return false;

After investigation, it is found that the current Widget is a sub -window. NativeEvent can only receive Windows system messages only when Nativa Windows, so it is necessary to process USB related events in the Native window.

source

Random Posts

noip2011 to improve the carpet of the first question group

matrix multiplication

SpringBoot picture upload Nginx proxy virtual link back display

ubuntu20.04 Virtual environment creation and use Ubuntu20.04 to create a virtual development environment

Windows qtcreator use qWebengineView Yulong