Results 1 to 1 of 1

Thread: USB HID Connection somehow impossible?

  1. #1
    Join Date
    Nov 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default USB HID Connection somehow impossible?

    Hey there,

    I'm currently working on my project in which I use an AVR microcontroller to measure some data and send it to my computer via USB. I used some code and circuit examples from obdev.at (vusb) in which I decided to use HID-Classes.

    My computer sees the device within my system configurations. Because it's an HID device, all other websites and references ask me to use HIDAPI (http://www.signal11.us/oss/hidapi/). It's a special kind of libusb (I guess) which is optimized for USB-HID communication. So I use the hidapi.h for MAC OSX and Linux (the windows platform will be there in future).

    Nevertheless pure C++ Code is working pretty well and I can open my device with HIDAPI and no problems occur.

    In the following code everything works pretty well:
    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QApplication>
    3.  
    4. #include <iostream>
    5. #include "hidapi.h"
    6. using namespace std;
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication::setOrganizationName("ThomasProducts");
    11. QCoreApplication::setOrganizationDomain("");
    12. QCoreApplication::setApplicationName("CLC");
    13. QCoreApplication::setApplicationVersion("alpha 0.1");
    14.  
    15. struct hid_device_info *devs, *cur_dev;
    16.  
    17. devs = hid_enumerate(0x0, 0x0);
    18. cur_dev = devs;
    19. while (cur_dev) {
    20. cout << "Device Found\n type: " << cur_dev->vendor_id << " " << cur_dev->product_id << endl;
    21. cur_dev = cur_dev->next;
    22. }
    23. hid_free_enumeration(devs);
    24.  
    25. QApplication *app = new QApplication(argc, argv);
    26. return app->exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    But that leads only to "static" USB-Connections. So I have to plug in my device before I start my application. It should be dynamic so that I can plug my USB device at any time I would like to.

    In future use there will be a GUI by Qt and Database and so on… To use QtWidget and QtMainWindow I'm supposed to start my application with QApplication. So here is an example for my real Project:
    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QApplication>
    3.  
    4. #include <iostream>
    5. #include "hidapi.h"
    6. using namespace std;
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication *app = new QApplication(argc, argv);
    11. QCoreApplication::setOrganizationName("ThomasProducts");
    12. QCoreApplication::setOrganizationDomain("");
    13. QCoreApplication::setApplicationName("CLC");
    14. QCoreApplication::setApplicationVersion("alpha 0.1");
    15.  
    16. struct hid_device_info *devs, *cur_dev;
    17.  
    18. devs = hid_enumerate(0x0, 0x0);
    19. cur_dev = devs;
    20. while (cur_dev) {
    21. cout << "Device Found\n type: " << cur_dev->vendor_id << " " << cur_dev->product_id << endl;
    22. cur_dev = cur_dev->next;
    23. }
    24. hid_free_enumeration(devs);
    25.  
    26. return app->exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    The second code gives me some major issues (see Backtrace.txt for more information). If I comment the QApplication *app line, and modify the return line everything works pretty well. Otherwise It will be like within the Backtrace.txt The only difference is the line in which QApplication is defined!

    Of course there are some other QWidgets I use, but in a nutshell this is just what happens in any case I try to establish the usb communication by Qt with HIDAPI. The source Code of the nutshell-programm is within the attachment.

    I'm stuck here! Is there any way to use QtApplication and HIDAPI in a simple program and manage the whole USB communication by a stand alone class within C++?

    I'm using Qt 5.5.0 on a Mac OSX Yosemite. If you need more information please ask me! I would be glad if someone got an idea about my problem.

    Greetings,
    Thomas
    Attached Files Attached Files

Similar Threads

  1. Is this impossible with PyQt4?
    By blanchoir in forum Newbie
    Replies: 4
    Last Post: 28th July 2011, 02:21
  2. Qt Designer Impossible to drag and drop the menu entry.
    By bred in forum Qt Tools
    Replies: 14
    Last Post: 27th October 2010, 06:21
  3. Replies: 37
    Last Post: 15th July 2009, 22:18
  4. Replies: 2
    Last Post: 27th April 2009, 15:15
  5. Impossible to build Qt with Gif support.
    By yellowmat in forum Installation and Deployment
    Replies: 4
    Last Post: 29th March 2006, 21:45

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.