Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qaudiodeviceinfo deviceName() truncates name to 31 char
Qt 6.11 is out! See what's new in the release blog

Qaudiodeviceinfo deviceName() truncates name to 31 char

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TimurIsk
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TimurIsk
        wrote on last edited by
        #3

        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;
        }@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved