Any way to detect usb device and print his path in QML?
-
Hi,
One possibility could be to use KDE’s Solid API.
-
@filipdns
This builds just fine, even on my Win10 system with Visual Studio 2017 and Qt 5.11.0. I just had to separately build two dependencies. UsingCMake-gui
, they are easy to configure: you must set a few variables for paths/files CMake cannot find;CMake-gui
makes the process almost self-explaining.ECM:
https://github.com/KDE/extra-cmake-modulesFlex/Bison:
https://sourceforge.net/projects/winflexbison/
For this one, I added the path of the build dir (containing bothwin_flex.exe
andwin_bison.exe
) to my system path so that CMake can find them.If it is that easy on Windows using VS2017, it must be even easier using MinGw or on Linux.
Mind you, I haven't tried using the lib yet. Hopefully, you will post about how you used it.
-
@Diracsbracket Thanks a lot.
Finaly I success to build it but still not able to use it yet.
I make small test to try:
First problem, I can not put QT += Solid on pro file because it return error:
:-1: erreur : LNK1181: cannot open input file 'Files.obj'
I try without with qml below:
import QtQuick 2.11 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Extras 1.4 import QtQuick.Controls 1.4 import QtQuick.LocalStorage 2.0 import QtQuick.Window 2.3 import QtQml 2.11 import QtQml.Models 2.11 import org.kde.solid 1.0 as Solid Window { visible: true width: 640 height: 480 Rectangle{ height:200 width:200 Solid.Devices { id: allDevices onDeviceAdded: console.log(allDevices.count) onCountChanged: {console.log(allDevices.count);number.text=allDevices.count} onDeviceRemoved: console.log(allDevices.count) } Text { id:number color:"black" text: allDevices.count } } }
I got 13 display.
with insert usb device, no signal, then nothing is return by the first part of the qml and the number display dosn't change.:
Solid.Devices { id: allDevices onDeviceAdded: console.log(allDevices.count) onCountChanged: {console.log(allDevices.count);number.text=allDevices.count} onDeviceRemoved: console.log(allDevices.count) }
but re-run the application, I got 15 display, and remove this device again and run again, I have again 13 display, then allDevices.count is working...
So if you have more informations about Solid on .pro problem and about the signals problem, I will be happy to be informed ;-)
best regards
Philippe -
@Diracsbracket said in Any way to detect usb device and print his path in QML?:
Yes too bad.. I stay with my problem then... :..( -
@filipdns
From
https://stackoverflow.com/questions/29414329/is-there-a-qt-solution-for-detecting-usb-events-insertion-and-removal
I just tried this one: it seems to work!
https://github.com/wang-bin/qdevicewatcher
You should be able to wrap it inside a QML class or pass it to the QML context. -
@Diracsbracket Thank you very much.
I will check that tomorrow.
Just in case and save time, do you know how I have to write the main.cpp with this qdevicewatcher to be able to receive the device path and the add and remove string to my qml?
It's very small part of my project and if I can do not lost time for that it can be nice if you know what I mean ;-)
Kind regards
Philippe -
@filipdns said in Any way to detect usb device and print his path in QML?:
It's very small part of my project and if I can do not lost time for that it can be nice if you know what I mean ;-)
Sorry, I cannot spend more time on that either. But I'm sure you will find it very quickly. Tomorrow.
It's not that difficult.Good luck.
Paul -
@Diracsbracket Hello, I understand, thank you for your help.
Philippe
-
@Pablo-J.-Rogina hello, that is not the case, I still trying to found solution.
Kind regards
Philippe -
@filipdns said in Any way to detect usb device and print his path in QML?:
that is not the case,
Does
QDeviceWatcher
not work? On my system, it correctly detects insertions and removals but maybe the ID's are not correctly reported as is. -
@Diracsbracket hello, it probably working but I didn't understand how I have to work with yet...
-
@Diracsbracket About Id I don't need it, I need only to have drive path display in qml text... but in c++ I very beginner