QMediaPlayer Fails with linker errors [SOLVED]



  • Below is my code for a very basic player however I am getting a ton of linker errors. Which i have no idea how to solve.

    main.cpp
    @
    #include <QDebug>
    #include <QApplication>
    #include <QMediaPlayer>
    //#include <QVideoWidget>
    #include <QtMultimediaWidgets/QVideoWidget>
    #include <QVBoxLayout>
    #include <QFile>

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

    QWidget *widget = new QWidget;
    widget->resize(400, 300);
    
    QVBoxLayout *layout = new QVBoxLayout;
    QMediaPlayer* player = new QMediaPlayer;
    QVideoWidget* vw = new QVideoWidget;
    
    layout->addWidget(vw);
    widget->setLayout(layout);
    
    player->setVideoOutput(vw);
    QFile file&#40;"big_buck_bunny_480p_surround-fix.avi"&#41;;
    if(!file.open(QIODevice::ReadOnly&#41;)
        qDebug() << "Could not open file";
    player->setMedia(QUrl::fromLocalFile&#40;"big_buck_bunny_480p_surround-fix.avi"&#41;&#41;;
    player->play();
    widget->show();
    qDebug() << player->availableMetaData() << player->currentMedia().canonicalUrl();
    return app.exec&#40;&#41;;
    

    }
    @

    RTSP.pro
    @#-------------------------------------------------

    Project created by QtCreator 2014-07-22T14:42:07

    #-------------------------------------------------

    QT += core gui multimedia

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = RTSP
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui@

    Any help on how to proceed from here would be great as pretty lost where to go from here.
    Thanks



  • Could you put some of the error messages here.


  • Lifetime Qt Champion

    Hi,

    You are missing

    @QT += multimediawidgets@

    In you pro file



  • Ah ok weird that fixed it, don't suppose you can explain why this worked cause I presumed by using:

    #include <QtMultimediaWidgets/QVideoWidget>

    I thought i didn't have to include it inside the pro file. Don't suppose you have any good links to explain the .pro file, cause I thought it was just another method of include.



  • "Here":http://qt-project.org/doc/qt-5/qmake-manual.html is some info about .pro and its "variables":http://qt-project.org/doc/qt-5/qmake-variable-reference.html

    There is a qmake line in a C++ class doc that specifies what Qt module to add to "QT":http://qt-project.org/doc/qt-5/qmake-variable-reference.html#qt variable to use the class. For example in "QVideoWidget Class":http://qt-project.org/doc/qt-5/qvideowidget.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.