Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

USB Device not found



  • Hi

    I am new to Qt and Android development so please be kind.

    I am trying to talk to a USB device using Qt and LibUsb-1.0.23.

    I have set up the AndroidManifest as follows and the USB device is detected and the application automatically opened upon connecting the USB device so all good.
    I also have 'Serial USB Terminal' installed which can see the device has the correct VID and PID as defined in the device_filter.xml.

    However the call to libusb_get_device_list always returns 0.

    Is there some other android access/permission setting I am missing?
    Any help greatly appreciated as I have spent a lot of time on this. TIA

    <?xml version="1.0"?>
    <manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="-- %%INSERT_VERSION_NAME%% --" android:versionCode="-- %%INSERT_VERSION_CODE%% --" android:installLocation="auto">
    <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
    Remove the comment if you do not require these default permissions. -->
    <!-- %%INSERT_PERMISSIONS -->
    <uses-permission android:name="android.permission.USB_PERMISSION"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
         Remove the comment if you do not require these default features. -->
    <!-- %%INSERT_FEATURES -->
    <uses-feature android:name="android.hardware.usb.host"/>
    
    <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
    <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:extractNativeLibs="true">
        <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
            </intent-filter>
            <!-- Application arguments -->
            <!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
            <!-- Application arguments -->
            <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter"/>
            <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
    

    Calling code from Qt
    // get list of usb
    libusb_context* context;
    int result = libusb_init (&context);
    if (result < 0)
    {
    restartOk = false;
    qDebug() <<"UNABLE_INITAILIZE_LIBUSB";
    }

    ssize_t cnt; // holding number of devices in list
    libusb_device **list_of_devices;
    cnt = libusb_get_device_list(context, &list_of_devices);

Log in to reply