Qt World Summit: Submit your Presentation

QT with USB

  • HI ,guys
    I get job last week;the Manager want me to transplant a vc6 project into Qt;
    I got all the codes;
    but here is a question I come across:
    in vc6 we can send a control message to a usb device by function "DeviceIoControl" in MSDN:
    The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the corresponding operation.

    BOOL DeviceIoControl(
    HANDLE hDevice, // handle to device
    DWORD dwIoControlCode, // operation
    LPVOID lpInBuffer, // input data buffer
    DWORD nInBufferSize, // size of input data buffer
    LPVOID lpOutBuffer, // output data buffer
    DWORD nOutBufferSize, // size of output data buffer
    LPDWORD lpBytesReturned, // byte count
    LPOVERLAPPED lpOverlapped // overlapped information
    I found this funcjtion in the vc project .but for a Qt project how to write/read datas into a USB device?

  • Qt Champions 2020

    This DeviceIoControl() function is a part of Win32 API, and does not related to Qt at all. So, you can use this function as well as in VS. Please read the MSDN to find out a Win-API headers which need to include to your project.

  • @kuzulis
    another question I got DLL build by vc6 ,here is the function inside:
    #ifndef DLL_API
    #define DLL_API extern "C" __declspec(dllimport)

    #define WIN_API __stdcall

    DLL_API void WINAPI HTDrawTopPentagon(HDC hDC,int nCenterX,int nCenterY,COLORREF clr);
    in QT I wang to use these funtions.
    will it work if I program like this:
    QLibrary myLib("dll_name");

    typedef int (*MyPrototype)(QPixmap* ,int,int,QColor);
    MyPrototype myFunction = (MyPrototype) myLib.resolve("HTDrawTopPentagon");

    myFunction test;
    will test work?
    or should i typedef int (*MyPrototype)(HDC ,int,int,COLORREF);in QT?

  • Qt Champions 2020

    or should i typedef int (*MyPrototype)(HDC ,int,int,COLORREF);in QT?


  • Hi,
    Because Qt is cross platform using a WinAPI is bad form. Shouldn't you switch to libusb making it cross platform?

Log in to reply