Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Transfer Files from Qt Creator to External USB Port
Forum Updated to NodeBB v4.3 + New Features

Transfer Files from Qt Creator to External USB Port

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 6 Posters 7.5k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    Jimit Rupani
    wrote on last edited by
    #1

    Re: USB Communication Using Qt
    I am a newb in Qt. I am looking for someone to help me with a problem "to transfer files from Ubuntu to External USB Drive".
    #qt

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      The OS should do all the work for you, QFile::copy() should be enough to achieve what you want

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • J Offline
        J Offline
        Jimit Rupani
        wrote on last edited by
        #3

        It's a project that needs undefined USBs. Means path of the Pendrive will change with new Pendrive. So is there any way to get the path of that device dynamically and use it to copy files to that device.

        Can't find the way to do that.

        J.HilkJ 1 Reply Last reply
        0
        • J Jimit Rupani

          It's a project that needs undefined USBs. Means path of the Pendrive will change with new Pendrive. So is there any way to get the path of that device dynamically and use it to copy files to that device.

          Can't find the way to do that.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Jimit-Rupani
          you can use QStorageInfo::mountedVolumes . Connected USB-Drives should be part of that list.

          foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
                    if (storage.isValid() && storage.isReady()) {
                        if (!storage.isReadOnly()) {
                            // ...
                        }
                    }
                }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          J 1 Reply Last reply
          1
          • J Offline
            J Offline
            Jimit Rupani
            wrote on last edited by
            #5

            I have solved the problem with the QStorageInfo::mountedVolumes() which return the list of the devices that are connected to the Machine.But all of them won't have a name except the Pendrive or HDD. So (!(storage.name()).isEmpty())) it will return the path to only those devices.

            QString location;
            QString path1= "/Report/1.txt";
            QString locationoffolder="/Report";
            
            foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
                      if (storage.isValid() && storage.isReady() && (!(storage.name()).isEmpty())) {
                          if (!storage.isReadOnly()) {
            
                             qDebug() << "path:" << storage.rootPath();
                             //WILL CREATE A FILE IN A BUILD FOLDER
                             location = storage.rootPath();
                             QString srcPath = "writable.txt";
                             //PATH OF THE FOLDER IN PENDRIVE
                             QString destPath = location+path1;
                             QString folderdir = location+locationoffolder;
                             //IF FOLDER IS NOT IN PENDRIVE THEN IT WILL CREATE A FOLDER NAME REPORT
                             QDir dir(folderdir);
                             if(!dir.exists()){
                                dir.mkpath(".");
                             }
            
                             qDebug() << "Usbpath:" <<destPath;
                             if (QFile::exists(destPath)) QFile::remove(destPath);
                             QFile::copy(srcPath,destPath);
                             qDebug("copied");
            
                          }
                      }
                }
            }
            

            I had to create a folder as well as in USB because of my requirements and I have given a static name for the files. then I just copied the data from file of the local machine to the file which I have created in USB with the help of QFile::copy(srcPath, dstPath). I hope this will help someone.

            1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @Jimit-Rupani
              you can use QStorageInfo::mountedVolumes . Connected USB-Drives should be part of that list.

              foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
                        if (storage.isValid() && storage.isReady()) {
                            if (!storage.isReadOnly()) {
                                // ...
                            }
                        }
                    }
              
              J Offline
              J Offline
              Jimit Rupani
              wrote on last edited by
              #6

              @J.Hilk I did and it solved my problem. thank you for the help!!

              jsulmJ 1 Reply Last reply
              1
              • J Jimit Rupani

                @J.Hilk I did and it solved my problem. thank you for the help!!

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Jimit-Rupani Maybe libusb could help you: http://libusb.sourceforge.net/api-1.0/hotplug.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Jimit-Rupani Maybe libusb could help you: http://libusb.sourceforge.net/api-1.0/hotplug.html

                  J Offline
                  J Offline
                  Jimit Rupani
                  wrote on last edited by
                  #8

                  @jsulm I have already try that all I got is just P.Id and V.id of pen drive. but I am not able to transfer the data from the machine. our project will deploy in a machine and from there it has to transfer data from machine to USB connected to it's port. from above solution, i am able to transfer data from PC to ps's USB port. But it's not working with the device. and thank you for the suggestions.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    What are you running on that device of yours ?

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

                    J 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Hi,

                      What are you running on that device of yours ?

                      J Offline
                      J Offline
                      Jimit Rupani
                      wrote on last edited by
                      #10

                      @SGaist It's a device from toradex which is using light weight linux. it'a titration device.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        What distribution is your "light weight linux" ?

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

                        J 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          What distribution is your "light weight linux" ?

                          J Offline
                          J Offline
                          Jimit Rupani
                          wrote on last edited by
                          #12

                          @SGaist yup it's light weight and we don't have console also in that devices Linux.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            What are you using for device handling with your distribution ?

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

                            Akshay SinghA 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              What are you using for device handling with your distribution ?

                              Akshay SinghA Offline
                              Akshay SinghA Offline
                              Akshay Singh
                              wrote on last edited by
                              #14

                              @SGaist sorry i didn't get you?

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                What service/library/etc. are you using on your target to handle devices that you connect to it through USB (e.g. udev) ?

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

                                1 Reply Last reply
                                0

                                • Login

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