Results 1 to 10 of 10

Thread: Detection usb device connection/disconnection

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Detection usb device connection/disconnection

    Hi,
    I made a response to this awhile back, see this thread. http://www.qtcentre.org/forum/f-qt-p...ent-18311.html
    I am using QtEmbedded Linux. I got the USB device info (vendor id, etc) from the /proc/scsi/usb-storage file. I use a thread to monitor the existence of that file, amongst other things. Here is just a snippet of parsing that file, just for the vendor name so I can display it on a QLabel
    Qt Code:
    1. responseConnection->hide();
    2. QFile fileInfo;
    3. QString usbInfoRaw, usbInfo;
    4. QDir usbInfoDir(USBINFODIR);
    5. if(!usbInfoDir.entryList(QDir::Files).isEmpty())
    6. {
    7. qDebug() << usbInfoDir;
    8. fileInfo.setFileName(USBINFODIR + usbInfoDir.entryList(QDir::Files).first());
    9. if(!fileInfo.open(QIODevice::ReadOnly | QIODevice::Text))
    10. qWarning() << "Can't Get File" << fileInfo.fileName();
    11. QTextStream in(&fileInfo);
    12. QTextStream out(&usbInfoRaw);
    13. out << in.read(100) << endl;
    14. usbInfo = usbInfoRaw.section(':',1,3);
    15. usbInfo.remove("Vendor:",Qt::CaseInsensitive);
    16. usbInfo.remove("Product:",Qt::CaseInsensitive);
    17. usbInfo.remove("usb-storage",Qt::CaseInsensitive);
    18. usbInfo.remove("Serial Number",Qt::CaseInsensitive);
    19. usbInfo = usbInfo.simplified();
    20. usbInfo.append(" ");
    21. }
    22. else
    23. qWarning() << "No File in Usb-storage";
    24. usbInfo.append(textDetect);
    25. uiResponseWin->label->setText(usbInfo);
    26. responseWindow->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by QbelcorT; 19th June 2009 at 04:43.

  2. The following user says thank you to QbelcorT for this useful post:

    saleh1 (26th August 2012)

Similar Threads

  1. QtExtended Porting on ARM Device - Color Problem
    By ramsarvan in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 19th February 2009, 06:32
  2. Replies: 0
    Last Post: 18th October 2008, 23:01
  3. No network when Modem Emulator connect to a real device
    By tommy_tang in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 10th December 2007, 08:24
  4. USB device detection problem
    By yellowmat in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2006, 12:04
  5. how to export images of Qt/Embedded on Device
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd March 2006, 12:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.