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. undefined reference errors using QtMultimedia in qt 6.8.3 c++
Forum Updated to NodeBB v4.3 + New Features

undefined reference errors using QtMultimedia in qt 6.8.3 c++

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 441 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.
  • A Offline
    A Offline
    andi456
    wrote last edited by andi456
    #1

    Hi,

    for some reason the ld does not seem to find the references to the QtMultimedia objects, I'd like to use. In my .h file, I have the following two lines after #include <QtMultimedia/QAudioOutput> and #include <QtMultimedia/QMediaPlayer>:

    QAudioOutput *aout;
    QMediaPlayer *player;
    

    the objects are then instantiated in my .cpp file like this:
    player = new QMediaPlayer();
    aout = new QAudioOutput();

    I followed pretty much the instructions in from the audio overview.
    My aim is rather simple: Playing a sound after some seconds. An example of the errors occuring:
    Error: /home/andi/Projekte/qt/Countdown/qcountdown.cpp:13:(.text+0x557): undefined reference to `QAudioOutput::QAudioOutput(QObject)'*

    Btw., I'm using a recent version of qtcreator on a gentoo linux box.

    Kind regards,

    Andreas

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      You do not link against the QtMultmedia library: https://doc.qt.io/qt-6/qaudiooutput.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andi456
        wrote last edited by
        #3

        If I try
        #include <QAudioOutput>
        the compiler tells me: no such file or directory. So how could I make the compiler or linker happy?

        SGaistS 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote last edited by
          #4

          I gave you a link where it's documented what you have to do when using qmake or cmake...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A andi456

            If I try
            #include <QAudioOutput>
            the compiler tells me: no such file or directory. So how could I make the compiler or linker happy?

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #5

            @andi456 hi,

            Including a header is not sufficient to "use" a library.

            As pointed by @Christian-Ehrlicher, you have to tell the build system that you intend to use said libraries.

            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
            • C Offline
              C Offline
              CJF the Elder
              wrote last edited by
              #6

              If you have to put forward slashes in a Qt include directive to find the file means you are hosed, or without forward slashes, it can't be found. QAudio is a module that requires you to edit the CMakeLists file and add the reference in two places. I had to do the same thing for Charts and SerialPort.

              under the packages, heading i need serialport and charts:
              find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
              find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
              find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS SerialPort)
              find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Charts)

              and here i have to add the libs for linking:
              target_link_libraries(myProject PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
              target_link_libraries(myProject PRIVATE
              Qt${QT_VERSION_MAJOR}::SerialPort
              Qt${QT_VERSION_MAJOR}::PrintSupport
              Qt${QT_VERSION_MAJOR}::Charts)

              Christian EhrlicherC 1 Reply Last reply
              0
              • C CJF the Elder

                If you have to put forward slashes in a Qt include directive to find the file means you are hosed, or without forward slashes, it can't be found. QAudio is a module that requires you to edit the CMakeLists file and add the reference in two places. I had to do the same thing for Charts and SerialPort.

                under the packages, heading i need serialport and charts:
                find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
                find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
                find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS SerialPort)
                find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Charts)

                and here i have to add the libs for linking:
                target_link_libraries(myProject PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
                target_link_libraries(myProject PRIVATE
                Qt${QT_VERSION_MAJOR}::SerialPort
                Qt${QT_VERSION_MAJOR}::PrintSupport
                Qt${QT_VERSION_MAJOR}::Charts)

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote last edited by
                #7

                @CJF-the-Elder that's exactly what's written in the docs I linked...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andi456
                  wrote last edited by andi456
                  #8

                  Thanks for the answers. I figured it out for the cmake build system.

                  For anyone who stumbles across a similar problem. I had to edit three lines in CMakeLists.txt, i.e., essentially add the keyword "Multimedia" to them:
                  find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia)
                  find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia)

                  target_link_libraries(Countdown PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia)

                  After that compiler and linker do find the corresponding files.

                  1 Reply Last reply
                  0
                  • A andi456 has marked this topic as solved

                  • Login

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