Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Playing audio in QML
Qt 6.12 LTS is out! See what's new in the release blog

Playing audio in QML

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.2k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I am trying to create a JukeBox program. I have started by trying to play audio in QML. I am using phonon module to create a class that is able to play an audio file and then I have registered this in QML. I am obviously making a fundamental error as I get following issues when trying to run it:

    error: symbol(s) not found for architecture x86_64
    error: collect2: ld returned 1 exit status

    here is my code, there is not much to it:

    in JukeBox.pro I added

    @QT += core gui phonon declarative@

    qmlaudio.h

    @#ifndef QMLAUDIO_H
    #define QMLAUDIO_H

    #include <phonon>
    #include <QDeclarativeItem>
    #include <QUrl>

    class QmlAudio : public QDeclarativeItem
    {
    Q_OBJECT
    public:
    QmlAudio(QDeclarativeItem *parent = 0);

    public slots:
    void setSong(const QUrl & songUrl);
    void play();

    private:

    Phonon::MediaObject *audioObject;
    

    };

    #endif // QMLAUDIO_H
    @

    qmlaudio.cpp

    @#include "qmlaudio.h"
    #include <QObject>
    #include <phonon>

    QmlAudio::QmlAudio(QDeclarativeItem *parent) : QDeclarativeItem(parent)
    {

    audioObject = Phonon::createPlayer(Phonon::MusicCategory,
                                       Phonon::MediaSource("/Users/jankokajtez/My Docs/Qt Projects/JukeBox/qml/JukeBox/song.mp3"));
    

    }

    void QmlAudio::setSong(const QUrl & songUrl)
    {
    audioObject->setCurrentSource(Phonon::MediaSource(songUrl));
    }

    void QmlAudio::play()
    {
    audioObject->play();
    }
    @

    main.cpp

    @#include <QtGui/QApplication>
    #include <QtDeclarative>
    #include "qmlaudio.h"

    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QDeclarativeView viewer;
    qmlRegisterType<QmlAudio>("qmlAudio", 1, 0, "QmlAudio");
    viewer.setSource(QUrl("/Users/jankokajtez/My Docs/Qt Projects/JukeBox/qml/JukeBox/main.qml"));
    viewer.show();
    
    return app.exec();
    

    }@

    main.qml

    @import QtQuick 1.0
    import qmlAudio 1.0

    Rectangle{
    id: mainScreen
    height: 900
    color: "#363636"
    width: 1440

    QmlAudio{
        id: song;
    }
    
    Text {
        id: playButton
        x: 394
        y: 482
        width: 85
        height: 67
        text: qsTr("PLAY")
        font.pixelSize: 30
        anchors.centerIn: parent
    
        MouseArea{
            id:playButtonMouseArea
            anchors.fill: parent
            onClicked: song.play()
        }
    }
    

    }@

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      People here have a similar issue(though not with playing audio), but yes error messages are same:

      http://developer.qt.nokia.com/forums/viewthread/6924

      Are there any more compiler generated statements btw, if yes try pasting it here.

      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
      • Unsolved