Linker Error in Visual Studio Project
-
Hi,
I want to play a video in a project i made. I am using Visual Studio 2015 as my IDE for QT development.
In .h file, I have included :
#include <QtMultimedia\qmediaplayer.h> #include <QtMultimediaWidgets\qvideowidget.h> #include <qtimer.h>
Below is my code file:
#include "firstvideo.h" FirstVideo::FirstVideo(QWidget *parent) : QDialog(parent) { ui.setupUi(this); player = new QMediaPlayer(this); vWidget = new QVideoWidget(this); player->setVideoOutput(vWidget); QString filename = "./SampleVideo_720x480_1mb.mp4"; player->setMedia(QUrl::fromLocalFile(filename)); player->setVolume(100); QTimer::singleShot(2000, this, SLOT(playMedia())); } FirstVideo::~FirstVideo() { } void FirstVideo::playMedia() { vWidget->setFullScreen(true); vWidget->show(); player->play(); }
Below is the error:
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QVideoWidget::QVideoWidget(class QWidget *)" (__imp_??0QVideoWidget@@QEAA@PEAVQWidget@@@Z) referenced in function "public: __cdecl FirstVideo::FirstVideo(class QWidget *)" (??0FirstVideo@@QEAA@PEAVQWidget@@@Z) FirstQT C:\Users\Megis_Student\Documents\Visual Studio 2015\Projects\FirstQT\FirstQT\firstvideo.obj
Can some one guide me on how to resolve this?
Thanks,
Anurag[Added code tags ~kshegunov]
-
What Qt version are you using?
With which compiler was it built?
Have you addedQT += multimediawidgets
to your project file?
Could you show what you havein the Qt project file? -
Thanks for the info. I was able to solve this by adding "Qt5Multimedia.lib" and "Qt5MultimediaWidgets.lib" reference at Properties->Linker->Input->Additional Dependencies.
After this, when I run the program in DEBUG mode, i get fellowing error:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is FirstVideo(0x1ad2f5c7970), parent's thread is QThread(0x1ad2f5270c0), current thread is QThread(0x1ad2f5d36d0)
QWidget: Must construct a QApplication before a QWidget
Unhandled exception at 0x00007FFAFDE8B70E (ucrtbase.dll) in FirstQT.exe: Fatal program exit requested.Using breakpoint, I found that I get this error at: player = new QMediaPlayer(this);
statement.But when i run in RELEASE mode, I do not get this error and the video plays. Why does this happen? None of classes inherit thread class.
The flow of program is:
main -> create object of MainWindows -> create a dialog for some Graphics view show -> after showing a graphics, close dialog -> Create object of FirstVideo (as above) -> in constructor of First Video create media player instance and play media. This is a naive project, not well organized, so I fear if i will run into some thread issues? I am creating dialogs from Mainwindow and once work of a dialog is complete, I pop a new dialog to show next graphics/video. Some tips will help.Also, is .pro file created when creating QT application from visual studio? I cannot find it in my project folder. Can it be generated and if yes, then how?
Thanks,
Anurag -
Thanks for the info. I was able to solve this by adding "Qt5Multimedia.lib" and "Qt5MultimediaWidgets.lib" reference at Properties->Linker->Input->Additional Dependencies.
Windows programs must use debug DLLs when compiled as debug version. therfore you have to link
Qt5Multimediad.lib
andQt5MultimediaWidgetsd.lib
in that case. -
Hi,
I added debug dll links but i am still getting the same error in Debug mode. Another problem I am facing is with QMediaPlayer, I am creating an instance of Media player and play video in full screen. This works fine (in release mode). After that I added following connect
connect(fplayer, &QMediaPlayer::stateChanged, this, &FirstQT::play1Done);
That is once the video is fully played, then call play1Done method. After adding this connect the video is played in background and not shown on screen. I just hear the audio in background. After video finishes, play1Done() method is called as expected.
Can anyone help, why is my video not playing in foreground?
Thanks,
Anurag