Qt6 linux: no audio output via QAudioSink
-
Hi, I am porting my app to Qt6 and struggling to make
QAudioSink
produce any sound.
I am on Ubuntu 24.04, using Qt 6.4.2After various checks I think the issue is in the default choice of the audio device.
Qt5's default is:
alsa_output.pci-0000_00_1b.0.analog-stereo
On Qt6 I can only get one of these
Built-in Audio Analog Stereo
Built-in Audio Digital Stereo (HDMI)
These are the real hardware devices which are already managed by alsa / pulse / pipewire, and cannot be used directly.
Qt5 plays a virtual alsa device which is mixed by the audio system.How do I do the same in Qt6? I've read about
QT_MEDIA_BACKEND=gstreamer
orffmpeg
but it makes no difference.Andrea
-
Hi,
How did you set that environment variable ?
-
Finally found a solution.
It is a change in behaviour between Qt5 and Qt6.
When the
QIODevice
produces 0 bytes, in Qt6, theQAudioSink
goes toIdleState
and effectively stops, even if more data is available.One needs to
emit readyRead();
when more data is available.In Qt5, nothing of the sort happens.
These are links to particular implementations of the output plugin, I have no way to know if this is the intended general behaviour, which anyway is not documented anywhere in https://doc.qt.io/qt-6/qaudiosink.html
-
The multimedia module has been fully rewritten for Qt 6.
That said, the current behavior makes sens to me and I would say the Qt 5 implementation was wrong in that regard. How is the system supposed to know you are making new data available if you don't tell it ? The other option is to have an active polling which would just waste resources.
-
-
I am realizing I might be seeing this from the wrong perspective. Are you providing your own custom QIODevice ?