Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Any way to detect usb device and print his path in QML?

Any way to detect usb device and print his path in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
16 Posts 4 Posters 4.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    filipdns
    wrote on 1 Sept 2018, 10:31 last edited by
    #1

    Hello,

    I'm looking to make mediaplayer in QML with QT5.11 on windows 10 and I would like to have any new usb device detecting and autoload all included mp3 in a list.

    Do you know any way to detect USB device?

    Thank you for your help

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Sept 2018, 19:45 last edited by
      #2

      Hi,

      One possibility could be to use KDE’s Solid API.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply 1 Sept 2018, 22:06
      3
      • S SGaist
        1 Sept 2018, 19:45

        Hi,

        One possibility could be to use KDE’s Solid API.

        F Offline
        F Offline
        filipdns
        wrote on 1 Sept 2018, 22:06 last edited by
        #3

        @SGaist Hi,

        I try that but I not able to build this, cmake request modules ECM and on the KDE documentation, I understand almost nothing, they send me to link then an other and an other... nothing work following what they say...

        D 1 Reply Last reply 2 Sept 2018, 07:49
        0
        • F filipdns
          1 Sept 2018, 22:06

          @SGaist Hi,

          I try that but I not able to build this, cmake request modules ECM and on the KDE documentation, I understand almost nothing, they send me to link then an other and an other... nothing work following what they say...

          D Offline
          D Offline
          Diracsbracket
          wrote on 2 Sept 2018, 07:49 last edited by Diracsbracket 9 Mar 2018, 04:12
          #4

          @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. Using CMake-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-modules

          Flex/Bison:
          https://sourceforge.net/projects/winflexbison/
          For this one, I added the path of the build dir (containing both win_flex.exe and win_bison.exe) to my system path so that CMake can find them.

          0_1535947948896_c523da71-e7a2-4ce6-a20f-9e8781b060f0-image.png

          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.

          F 1 Reply Last reply 2 Sept 2018, 14:45
          4
          • D Diracsbracket
            2 Sept 2018, 07:49

            @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. Using CMake-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-modules

            Flex/Bison:
            https://sourceforge.net/projects/winflexbison/
            For this one, I added the path of the build dir (containing both win_flex.exe and win_bison.exe) to my system path so that CMake can find them.

            0_1535947948896_c523da71-e7a2-4ce6-a20f-9e8781b060f0-image.png

            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.

            F Offline
            F Offline
            filipdns
            wrote on 2 Sept 2018, 14:45 last edited by
            #5

            @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

            D 1 Reply Last reply 3 Sept 2018, 12:10
            0
            • F filipdns
              2 Sept 2018, 14:45

              @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

              D Offline
              D Offline
              Diracsbracket
              wrote on 3 Sept 2018, 12:10 last edited by
              #6

              @filipdns
              I tried on both Windows 10 and Linux. Although the plugin builds,
              it just doesn't work as advertised, even for the simplest of examples.
              Too bad...

              F 1 Reply Last reply 3 Sept 2018, 17:53
              1
              • D Diracsbracket
                3 Sept 2018, 12:10

                @filipdns
                I tried on both Windows 10 and Linux. Although the plugin builds,
                it just doesn't work as advertised, even for the simplest of examples.
                Too bad...

                F Offline
                F Offline
                filipdns
                wrote on 3 Sept 2018, 17:53 last edited by
                #7

                @Diracsbracket said in Any way to detect usb device and print his path in QML?:
                Yes too bad.. I stay with my problem then... :..(

                D 1 Reply Last reply 3 Sept 2018, 18:01
                0
                • F filipdns
                  3 Sept 2018, 17:53

                  @Diracsbracket said in Any way to detect usb device and print his path in QML?:
                  Yes too bad.. I stay with my problem then... :..(

                  D Offline
                  D Offline
                  Diracsbracket
                  wrote on 3 Sept 2018, 18:01 last edited by Diracsbracket 9 Mar 2018, 18:06
                  #8

                  @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.

                  F 1 Reply Last reply 3 Sept 2018, 22:46
                  3
                  • D Diracsbracket
                    3 Sept 2018, 18:01

                    @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.

                    F Offline
                    F Offline
                    filipdns
                    wrote on 3 Sept 2018, 22:46 last edited by
                    #9

                    @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

                    D 1 Reply Last reply 4 Sept 2018, 01:44
                    0
                    • F filipdns
                      3 Sept 2018, 22:46

                      @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

                      D Offline
                      D Offline
                      Diracsbracket
                      wrote on 4 Sept 2018, 01:44 last edited by Diracsbracket 9 Apr 2018, 02:42
                      #10

                      @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

                      F 1 Reply Last reply 4 Sept 2018, 06:59
                      1
                      • D Diracsbracket
                        4 Sept 2018, 01:44

                        @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

                        F Offline
                        F Offline
                        filipdns
                        wrote on 4 Sept 2018, 06:59 last edited by
                        #11

                        @Diracsbracket Hello, I understand, thank you for your help.

                        Philippe

                        P 1 Reply Last reply 5 Sept 2018, 18:03
                        0
                        • F filipdns
                          4 Sept 2018, 06:59

                          @Diracsbracket Hello, I understand, thank you for your help.

                          Philippe

                          P Offline
                          P Offline
                          Pablo J. Rogina
                          wrote on 5 Sept 2018, 18:03 last edited by
                          #12

                          @filipdns if your issue is solved please don't forget to mark your post as such. Thanks

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          F 1 Reply Last reply 6 Sept 2018, 07:43
                          0
                          • P Pablo J. Rogina
                            5 Sept 2018, 18:03

                            @filipdns if your issue is solved please don't forget to mark your post as such. Thanks

                            F Offline
                            F Offline
                            filipdns
                            wrote on 6 Sept 2018, 07:43 last edited by
                            #13

                            @Pablo-J.-Rogina hello, that is not the case, I still trying to found solution.

                            Kind regards
                            Philippe

                            D 1 Reply Last reply 6 Sept 2018, 08:28
                            0
                            • F filipdns
                              6 Sept 2018, 07:43

                              @Pablo-J.-Rogina hello, that is not the case, I still trying to found solution.

                              Kind regards
                              Philippe

                              D Offline
                              D Offline
                              Diracsbracket
                              wrote on 6 Sept 2018, 08:28 last edited by Diracsbracket 9 Jun 2018, 08:30
                              #14

                              @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.

                              F 2 Replies Last reply 6 Sept 2018, 09:10
                              1
                              • D Diracsbracket
                                6 Sept 2018, 08:28

                                @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.

                                F Offline
                                F Offline
                                filipdns
                                wrote on 6 Sept 2018, 09:10 last edited by
                                #15

                                @Diracsbracket hello, it probably working but I didn't understand how I have to work with yet...

                                1 Reply Last reply
                                0
                                • D Diracsbracket
                                  6 Sept 2018, 08:28

                                  @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.

                                  F Offline
                                  F Offline
                                  filipdns
                                  wrote on 6 Sept 2018, 09:36 last edited by
                                  #16

                                  @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

                                  1 Reply Last reply
                                  0

                                  7/16

                                  3 Sept 2018, 17:53

                                  • Login

                                  • Login or register to search.
                                  7 out of 16
                                  • First post
                                    7/16
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved