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];
34 this->QThread::start();
43 if (!StopDeviceNotifications(mNotificationHandle)) {
44 qWarning(
"StopDeviceNotifications() error: %d", GetLastError());
47 if (!CloseMsgQueue(mQueueHandle)) {
48 qWarning(
"CloseMsgQueue() error: %d", GetLastError());
57 MSGQUEUEOPTIONS msgopts;
59 msgopts.dwSize =
sizeof(MSGQUEUEOPTIONS);
61 msgopts.dwMaxMessages = 0;
62 msgopts.cbMaxMessage =
sizeof(Q_DEVDETAIL);
63 msgopts.bReadAccess = TRUE;
64 msgopts.dwMaxMessages = 0;
70 mQueueHandle = CreateMsgQueue(
nullptr, &msgopts);
71 if (mQueueHandle ==
nullptr) {
72 qWarning(
"CreateMsgQueue() error: %d", GetLastError());
75 mNotificationHandle = RequestDeviceNotifications(&BLOCK_DRIVER_GUID, mQueueHandle, TRUE);
76 if (mNotificationHandle ==
nullptr) {
77 qWarning(
"RequestDeviceNotifications() error: %d", GetLastError());
83 void QDeviceWatcherPrivate::run()
90 if(WaitForSingleObject(mQueueHandle, 3000) == WAIT_OBJECT_0) {
91 while(ReadMsgQueue(mQueueHandle, &detail,
sizeof(detail), &size, 1, &flags)) {
92 QString dev = TCHAR2QString(detail.d.szName);
94 if (detail.d.fAttached) {
103 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