Qaudiodeviceinfo deviceName() truncates name to 31 char



  • I face a problem enumerating audio input device using Qt 5.1.

    @QList<QAudioDeviceInfo> devicesList = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);

    for(int i = 0; i < devicesList.size(); ++i){
    qDebug() << "device " << i << devicesList.at(i).deviceName();
    }@

    The names are truncated to a max of 31 chars. For example is outputs:

    "Microphone (2- Périphérique aud"

    Is there a workaround to get the full name of the audio input device?

    Thanks in advance


  • Lifetime Qt Champion

    Hi,

    IIRC, that's a limitation of the Win32 API used in the backend so there's no easy workaround for that.

    On an unrelated note, please don't write complete thread title in uppercase. In written language it's considered shouting



  • SGaist, thank you.

    I found one way using IMMDeviceCollection.
    But it works only with win 7, and maybe win8.

    @LPWSTR SoundDeviceControler::GetDeviceName( IMMDeviceCollection *DeviceCollection, UINT DeviceIndex )
    {
    IMMDevice *device;
    LPWSTR deviceId;
    HRESULT hr;

    hr = DeviceCollection->Item(DeviceIndex, &device);
    if (FAILED(hr))
    {
    //printf("Unable to get device %d: %x\n", DeviceIndex, hr);
    return NULL;
    }
    hr = device->GetId(&deviceId);
    if (FAILED(hr))
    {
    //printf("Unable to get device %d id: %x\n", DeviceIndex, hr);
    return NULL;
    }

    IPropertyStore *propertyStore;
    hr = device->OpenPropertyStore(STGM_READ, &propertyStore);
    SafeRelease(&device);
    if (FAILED(hr))
    {
    //printf("Unable to open device %d property store: %x\n", DeviceIndex, hr);
    return NULL;
    }

    PROPVARIANT friendlyName;
    PropVariantInit(&friendlyName);
    hr = propertyStore->GetValue(PKEY_Device_FriendlyName, &friendlyName);
    SafeRelease(&propertyStore);

    if (FAILED(hr))
    {
    //printf("Unable to retrieve friendly name for device %d : %x\n", DeviceIndex, hr);
    return NULL;
    }

    wchar_t deviceName[128];
    hr = StringCbPrintf(deviceName, sizeof(deviceName), L"%s (%s)", friendlyName.vt != VT_LPWSTR ? L"Unknown" : friendlyName.pwszVal, deviceId);
    if (FAILED(hr))
    {
    //printf("Unable to format friendly name for device %d : %x\n", DeviceIndex, hr);
    return NULL;
    }

    PropVariantClear(&friendlyName);
    CoTaskMemFree(deviceId);

    wchar_t *returnValue = _wcsdup(deviceName);
    if (returnValue == NULL)
    {
    //printf("Unable to allocate buffer for return\n");
    return NULL;
    }
    return returnValue;
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.