Transfer Files from Qt Creator to External USB Port
-
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 -
The OS should do all the work for you, QFile::copy() should be enough to achieve what you want
-
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.
-
@Jimit-Rupani
you can useQStorageInfo::mountedVolumes
. Connected USB-Drives should be part of that list.foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid() && storage.isReady()) { if (!storage.isReadOnly()) { // ... } } }
-
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.
-
@Jimit-Rupani Maybe libusb could help you: http://libusb.sourceforge.net/api-1.0/hotplug.html
-
@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.
-
Hi,
What are you running on that device of yours ?
-
What distribution is your "light weight linux" ?
-
What are you using for device handling with your distribution ?
-
What service/library/etc. are you using on your target to handle devices that you connect to it through USB (e.g. udev) ?