-
Bug
-
Resolution: Incomplete
-
P2: Important
-
None
-
6.2.4
-
OS: Ubuntu 22.04 LTS
Qt version: 6.2.4
Hello,
I am building a desktop application on Ubuntu 22.04 using Qt 6.2.4. I use CMake (>=3.22.1) for the build configuration. I use Qt Creator (>=6.0.2) to build and run the application. It builds fine, but when I run it, I get warning messages and no sound plays.
Below is the source code.
#include <memory>
#include <QApplication>
#include <QAudioOutput>
#include <QFileInfo>
#include <QMediaPlayer>
#include <QObject>
#include <QString>
#include <QUrl>
#include <QWidget>
class SoundEffect : public QObject {
Q_OBJECT
public:
SoundEffect(QObject* aParent, const QString& aSound)
: QObject(aParent)
, mSound(aSound) {
}
void PlaySound() {
QFileInfo soundPath{mSound};
QString soundAbsPath{soundPath.absoluteFilePath()};
qDebug() << "soundAbsPath: " << soundAbsPath;
auto soundUrl = QUrl::fromLocalFile(soundAbsPath);
qDebug() << "soundUrl: " << soundUrl;
mOutput.setVolume(1.0);
mPlayer.setAudioOutput(&mOutput);
mPlayer.setSource(soundUrl);
mPlayer.setLoops(QMediaPlayer::Infinite);
mPlayer.play();
}
private:
QString mSound;
QAudioOutput mOutput;
QMediaPlayer mPlayer;
};
int main(int aArgc, char** aArgv) {
QApplication theApp{aArgc, aArgv};
auto theWidget = std::make_unique<QWidget>(nullptr);
theWidget->show();
SoundEffect theEffect{theWidget.get(), "mySound.mp3"};
theEffect.PlaySound();
int exitCode{theApp.exec()};
return exitCode;
}
Below is the console output.
Gtk-Message: 10:01:16.982: Failed to load module "xapp-gtk3-module"
Gtk-Message: 10:01:16.982: Failed to load module "unity-gtk-module"
Gtk-Message: 10:01:17.027: Failed to load module "canberra-gtk-module"
Gtk-Message: 10:01:17.028: Failed to load module "canberra-gtk-module"
Qt: Session management error: None of the authentication protocols specified are supported
soundAbsPath: "/home/compscidude/build-TestSound-Qt6-Debug/source/mySound.mp3"
soundUrl: QUrl("file:///home/compscidude/build-TestSound-Qt6-Debug/source/mySound.mp3")
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
qt.multimedia.player: Warning: "Failed to connect: Connection refused"
qt.multimedia.player: Warning: "Failed to connect: Connection refused"
Would someone be able to help me diagnose the issue?