QDeviceWatcher can detect usb storage add and remove event. Tested on linux (>= 2.6), windows(mingw and msvc) and OSX(buggy).
License under LGPL 2.1 or later
Detect the device changes. Support hotplug event for win and linux now.
A function that allows to disable the qdebug output when plugging or unplugging devices. This function should be usable externally if qdvicewatcher.h is included in the external code.
Hi, I am hoping you can help. I am using Win10, with Qt 5.12.2 and when I try to compile I am getting this error. Any help would be appreciated. I have tried with both MinGW64 and 32 bit. Here is my compile errors for both 32/64.
Thanks,
Rick
MinGW64
09:12:07: Running steps for project QDeviceWatcher...
09:12:07: Starting: "C:\Qt\Qt5.12.2\5.12.2\mingw73_64\bin\qmake.exe" "C:\Users\Rick Local\Desktop\QDeviceWatcher\qdevicewatcher-master\QDeviceWatcher.pro" -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
09:12:08: The process "C:\Qt\Qt5.12.2\5.12.2\mingw73_64\bin\qmake.exe" exited normally.
09:12:08: Starting: "C:\Qt\Qt5.12.2\Tools\mingw730_64\bin\mingw32-make.exe" -f "C:/Users/Rick Local/Desktop/QDeviceWatcher/build-QDeviceWatcher-Desktop_Qt_5_12_2_MinGW_64_bit-Debug/Makefile" qmake_all
0 [main] sh 13132 sync_with_child: child 17036(0x19C) died before initialization with status code 0xC0000142
29 [main] sh 13132 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
mingw32-make: *** [C:/Users/Rick Local/Desktop/QDeviceWatcher/build-QDeviceWatcher-Desktop_Qt_5_12_2_MinGW_64_bit-Debug/Makefile:37: sub-src-libQDeviceWatcher-pro-qmake_all] Error 129
09:12:08: The process "C:\Qt\Qt5.12.2\Tools\mingw730_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project QDeviceWatcher (kit: Desktop Qt 5.12.2 MinGW 64-bit)
When executing step "qmake"
09:12:08: Elapsed time: 00:00.
and with MinGW32
09:14:49: Running steps for project QDeviceWatcher...
09:14:49: Starting: "C:\Qt\Qt5.12.2\5.12.2\mingw73_32\bin\qmake.exe" "C:\Users\Rick Local\Desktop\QDeviceWatcher\qdevicewatcher-master\QDeviceWatcher.pro" -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
Info: creating stash file C:\Users\Rick Local\Desktop\QDeviceWatcher\build-QDeviceWatcher-Desktop_Qt_5_12_2_MinGW_32_bit-Debug.qmake.stash
09:14:49: The process "C:\Qt\Qt5.12.2\5.12.2\mingw73_32\bin\qmake.exe" exited normally.
09:14:49: Starting: "C:\Qt\Qt5.12.2\Tools\mingw730_32\bin\mingw32-make.exe" -f "C:/Users/Rick Local/Desktop/QDeviceWatcher/build-QDeviceWatcher-Desktop_Qt_5_12_2_MinGW_32_bit-Debug/Makefile" qmake_all
0 [main] sh 11132 sync_with_child: child 18004(0x1A0) died before initialization with status code 0xC0000142
16 [main] sh 11132 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
mingw32-make: *** [C:/Users/Rick Local/Desktop/QDeviceWatcher/build-QDeviceWatcher-Desktop_Qt_5_12_2_MinGW_32_bit-Debug/Makefile:37: sub-src-libQDeviceWatcher-pro-qmake_all] Error 129
09:14:50: The process "C:\Qt\Qt5.12.2\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project QDeviceWatcher (kit: Desktop Qt 5.12.2 MinGW 32-bit)
When executing step "qmake"
09:14:50: Elapsed time: 00:01.
#include <CoreServices/CoreServices.h>
#include <IOKit/storage/IOCDMedia.h>
#include <IOKit/storage/IODVDMedia.h>
Where can I get these files? I'm trying to compile but they are missing.
I'm copiling on windows are they needed only for mac ? if so how can I compile the project on windows avoiding the compiler to complain for that ?
because current implemention must run as a root user
DARegisterDiskAppearedCallback, DARegisterDiskDisappearedCallback
update qmake pro
I tried using the following simple code on Windows to detect when devices are inserted or removed:
QDeviceWatcher deviceWatcher;
QObject::connect(&deviceWatcher, &QDeviceWatcher::deviceAdded, [](){
qDebug() << "Device added";
});
QObject::connect(&deviceWatcher, &QDeviceWatcher::deviceChanged, [](){
qDebug() << "Device changed";
});
QObject::connect(&deviceWatcher, &QDeviceWatcher::deviceRemoved, [](){
qDebug() << "Device removed";
});
I tried inserting/removing several USB devices while this program was running, but none of these signals were ever emitted. The USB devices that I tried were a USB mouse and an Android phone with a USB cable.
in Qt4, we can use installEventFilter and QAbstractEventDispatcher(i haven't let it work) to deal with system events theoretically. In Qt5 a new class is introduced, QAbstractNativeEventFilter, a better one.
Hello,
I am confused with this point that I use qt5.5.1_msvc_32bit to build qdevicewatcher, But it happens unresolved external symbol about windows function, such as:
Creating library ..\out\lib_win_\QDeviceWatcherd2.lib and object ..\out\lib_win_\QDeviceWatcherd2.exp
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__DefWindowProcW@16 referenced in function "long __stdcall dw_internal_proc(struct HWND *,unsigned int,unsigned int,long)" (?dw_internal_proc@@YGJPAUHWND__@@iij@Z)
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__RegisterClassW@4 referenced in function "struct HWND * *cdecl dw_create_internal_window(void const )" (?dw_create_internal_window@@YAPAUHWND@@pbx@Z)
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__UnregisterClassW@8 referenced in function "void __cdecl dw_destroy_internal_window(struct HWND *)" (?dw_destroy_internal_window@@YAXPAUHWND__@@@z)
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__CreateWindowExW@48 referenced in function "struct HWND * *cdecl dw_create_internal_window(void const )" (?dw_create_internal_window@@YAPAUHWND@@pbx@Z)
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__DestroyWindow@4 referenced in function "void __cdecl dw_destroy_internal_window(struct HWND *)" (?dw_destroy_internal_window@@YAXPAUHWND__@@@z)
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__GetWindowLongW@8 referenced in function "long __stdcall dw_internal_proc(struct HWND *,unsigned int,unsigned int,long)" (?dw_internal_proc@@YGJPAUHWND__@@iij@Z)
qdevicewatcher_win32.obj : error LNK2019: unresolved external symbol imp__SetWindowLongW@12 referenced in function "struct HWND * *cdecl dw_create_internal_window(void const )" (?dw_create_internal_window@@YAPAUHWND@@pbx@Z)
..\out\lib_win_\QDeviceWatcherd2.dll : fatal error LNK1120: 7 unresolved externals
it points to windows function, Do I need to make some setting before build this project?
Your app compiles and runs fine. When I try to integrate the lib into my app I get "Bind: Address Already in Use". I tried to set SO_REUSEADDR as suggested here:
http://hea-www.harvard.edu/~fine/Tech/addrinuse.html
This did not help. I have integrated the files
qdevicewatcher.h
qdevicewatcher_p.h
qdevicewatcher.cpp
qdevicewatcher_linux.cpp
directly, not as a lib. My app builds without errors, but I get the bind() errormessage. Is there any idea how to overcome this issue?
Thanks in advance
I just tried to build the QDevicewatcher test app under Ubuntu 14.04, and it does not compile.
It seems that you use a mac for development, could that be true? Because I think that mac specific code is not removed by an #ifdef by the preprocessor - so it gets compiled under Linux as well and then the compiler doesn't find CoreServices.h and IOCDMedia.h + IODVDMedia.h
Did you try to compile the software/lib under Linux recently?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.