11
votes

I have a small C++ Qt program that uses a QAudioOutput instance to emit sound. It compiles & runs fine using Qt 4.8.5.

However, in Qt 5.0, 5.1, and 5.2, my application compiles, but does not work. I get the following error message while the constructor of the QAudioOutput instance is running:

Unable to create a connection to the pulseaudio context.

Also, the constructor does not return, so my program hangs.

I do not have pulseaudio running. ALSA is working fine, and this is what my program uses when compiled with Qt 4.8.5.

Inspecting the Qt5 “plugins/audio” directory, there is only “libqtmedia_pulse.so” there, the name of which suggests that it depends on pulseaudio.

My questions:

  • Is there still a backend for output to ALSA (without pulseaudio) in Qt 5+ ?
  • If yes, how do I make sure it is built? I do not see any configure options for that.
  • It appears to be a bug that the constructor of QAudioOutput hangs my app. Where can I report that?
3
Did you build Qt yourself? You may have to enable the ALSA audio plugin to get it to work. It should definitely be supported, according to the Qt Multimedia Backends document. You can also take a look at the QAudioDeviceInfo Class to see which audio devices were recognized.deGoot

3 Answers

4
votes

From Qt documentation wiki on Multimedia Backends:

Here is the list of the current audio backends:

Windows Multimedia
CoreAudio (Mac OS / iOS)
PulseAudio (Unix)
Alsa (Unix)
OpenSL ES (Android)
QNX

Only PulseAudio, CoreAudio, and QNX backends are actual plugins. The other backends are “#ifdef’ed” in the related classes.

So basically ALSA is not a plugin but must be selected when you configure Qt (if you build your own, which I assume you are).

From Qt documentation wiki on building Qt5 from git:

Qt Multimedia

You’ll need at least alsa-lib (>= 1.0.15) and gstreamer (>=0.10.24, but <1.0 for now [lists.qt-project.org]) with the base-plugins package.

Ubuntu/Debian:

sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

When configuring Qt I have lost count over the times when some feature was not compiled in because of missing dependencies. So make absolutely 100% sure that all dependencies are installed properly, and that all your configuration options are valid with the current configuration program (available options change even between minor versions)! Remember to look closely at output from build process (collect output in a file and search through it after build completes for any messages with "skipping" or "error" or such keywords.

OTOH, if you did not build your own Qt then I have no clue and you should disregard this answer.

0
votes

Fix is present in Qt 5.4, commit eb75bf8e3bde3a9b3efc91b54aa4dc2e34a3cde4


I'm the Debian maintainer for Qt and today a user came with the same problem. The build logs show that alsa dependencies are there and it's being properly detected... :-/

Note 2014-12-03: the problem lies in plugins.pro: it doesn't builds the alsa plugin if pulseaudio support is found. Problem and patch by Chris Ruvolo, will push upstream later today.

0
votes