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. Linker Error in Visual Studio Project
Forum Updated to NodeBB v4.3 + New Features

Linker Error in Visual Studio Project

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 3.3k 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
    Anurag2904
    wrote on 6 Jan 2018, 04:25 last edited by kshegunov 1 Jun 2018, 09:05
    #1

    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]

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 6 Jan 2018, 09:06 last edited by
      #2

      What Qt version are you using?
      With which compiler was it built?
      Have you added QT += multimediawidgets to your project file?
      Could you show what you havein the Qt project file?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Anurag2904
        wrote on 6 Jan 2018, 20:18 last edited by Anurag2904 1 Jun 2018, 20:19
        #3

        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

        A 1 Reply Last reply 6 Jan 2018, 20:35
        0
        • A Anurag2904
          6 Jan 2018, 20:18

          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

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 6 Jan 2018, 20:35 last edited by
          #4

          @Anurag2904

          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 and Qt5MultimediaWidgetsd.lib in that case.

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anurag2904
            wrote on 7 Jan 2018, 02:39 last edited by
            #5

            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

            1 Reply Last reply
            0

            1/5

            6 Jan 2018, 04:25

            • Login

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