8 #include <QtCore/QCoreApplication>
11 # if TTK_QT_VERSION_CHECK(4,0,0)
12 # define TCHAR2QString(x) QString::fromUtf16(x)
14 # define TCHAR2QString(x) QString::fromUcs2(x)
17 # define TCHAR2QString(x) QString::fromLocal8Bit((x))
22 char pad[
sizeof(DEVDETAIL) + MAX_DEVCLASS_NAMELEN];
42 if (!StopDeviceNotifications(mNotificationHandle)) {
43 qWarning(
"StopDeviceNotifications() error: %d", GetLastError());
46 if (!CloseMsgQueue(mQueueHandle)) {
47 qWarning(
"CloseMsgQueue() error: %d", GetLastError());
56 MSGQUEUEOPTIONS msgopts;
58 msgopts.dwSize =
sizeof(MSGQUEUEOPTIONS);
60 msgopts.dwMaxMessages = 0;
61 msgopts.cbMaxMessage =
sizeof(Q_DEVDETAIL);
62 msgopts.bReadAccess = TRUE;
63 msgopts.dwMaxMessages = 0;
69 mQueueHandle = CreateMsgQueue(
nullptr, &msgopts);
70 if (mQueueHandle ==
nullptr) {
71 qWarning(
"CreateMsgQueue() error: %d", GetLastError());
74 mNotificationHandle = RequestDeviceNotifications(&BLOCK_DRIVER_GUID, mQueueHandle, TRUE);
75 if (mNotificationHandle ==
nullptr) {
76 qWarning(
"RequestDeviceNotifications() error: %d", GetLastError());
82 void QDeviceWatcherPrivate::run()
89 if(WaitForSingleObject(mQueueHandle, 3000) == WAIT_OBJECT_0) {
90 while(ReadMsgQueue(mQueueHandle, &detail,
sizeof(detail), &size, 1, &flags)) {
91 QString dev = TCHAR2QString(detail.d.szName);
93 if (detail.d.fAttached) {
102 QCoreApplication::postEvent(obj, event, Qt::HighEventPriority);
void emitDeviceAdded(const QString &dev)
The class of the device watcher event.
void emitDeviceRemoved(const QString &dev)
QObjectList event_receivers