1

I have problems on building OpenCV_HighGui220d.lib with QT support. The problems are the unresolved symbols about QMetaObject, such as:

    public: virtual struct QMetaObject const * __thiscall GuiReceiver::metaObject(void)const (?metaObject@GuiReceiver@@UBEPBUQMetaObject@@XZ)

My Environments:
- Visual Studio 2010
- OpenCV 2.2
- QT SDK Version:4.7.3

Below are my building steps:
1. use CMake to open C:\OpenCV2.2, check on WITH_QT and WITH_QT_OPENGL, generate vcxproj and sln files.

2. add below macros in cvconfig.h:

#define HAVE_QT
#define HAVE_QT_OPENGL

3. add window_QT.cpp into opencv_highgui.vcxproj file in VS2010, and add below macros in window_QT.cpp
#define QT_LARGEFILE_SUPPORT
#define QT_DLL
#define QT_GUI_LIB
#define QT_CORE_LIB
#define QT_HAVE_MMX
#define QT_HAVE_3DNOW
#define QT_HAVE_SSE
#define QT_HAVE_MMXEXT
#define QT_HAVE_SSE2
#define QT_THREAD_SUPPORT
I also tried to replace QT_DLL with QT_NODLL, but did not succeed.

4. Add directory C:/QtSDK/Desktop/Qt/4.7.3/msvc2008/lib in Additional Library Directories in Linker Property pages.

5. Add below libraries in Additional Dependencies:
qtmain.lib
qtmaind.lib
QtGui4.lib
QtGuid4.lib
QtCore4.lib
QtCored4.lib
QtOpenGL4.lib
QtOpenGLd4.lib
Qt3Support4.lib
Qt3Supportd4.lib
QtHelp4.lib
QtHelpd4.lib
QtDesigner4.lib
QtDesignerd4.lib
QAxContainer.lib
QAxContainerd.lib
phonon4.lib
phonond4.lib
QAxServer.lib
QAxServerd.lib
QtDeclarative4.lib
QtDeclaratived4.lib
QtDesignerComponents4.lib
QtDesignerComponentsd4.lib
QtMultimedia4.lib
QtMultimediad4.lib
QtNetwork4.lib
QtNetworkd4.lib
QtScript4.lib
QtScriptd4.lib
QtScriptTools4.lib
QtScriptToolsd4.lib
QtSql4.lib
QtSqld4.lib
QtSvg4.lib
QtSvgd4.lib
QtTest4.lib
QtTestd4.lib
QtUiTools.lib
QtUiToolsd.lib
QtWebKit4.lib
QtWebKitd4.lib
QtXml4.lib
QtXmld4.lib
QtXmlPatterns4.lib
QtXmlPatternsd4.lib

6. Finally, the linker reports error:

------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------
------ Build started: Project: opencv_highgui, Configuration: Debug Win32 ------
     Creating library C:/OpenCV2.2/Build_QT/lib/Debug/opencv_highgui220d.lib and object C:/OpenCV2.2/Build_QT/lib/Debug/opencv_highgui220d.exp
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall GuiReceiver::metaObject(void)const " (?metaObject@GuiReceiver@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall GuiReceiver::qt_metacast(char const *)" (?qt_metacast@GuiReceiver@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall GuiReceiver::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@GuiReceiver@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvTrackbar::metaObject(void)const " (?metaObject@CvTrackbar@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvTrackbar::qt_metacast(char const *)" (?qt_metacast@CvTrackbar@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvTrackbar::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvTrackbar@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const CvTrackbar::staticMetaObject" (?staticMetaObject@CvTrackbar@@2UQMetaObject@@B)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvButtonbar::metaObject(void)const " (?metaObject@CvButtonbar@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvButtonbar::qt_metacast(char const *)" (?qt_metacast@CvButtonbar@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvButtonbar::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvButtonbar@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const CvButtonbar::staticMetaObject" (?staticMetaObject@CvButtonbar@@2UQMetaObject@@B)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvPushButton::metaObject(void)const " (?metaObject@CvPushButton@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvPushButton::qt_metacast(char const *)" (?qt_metacast@CvPushButton@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvPushButton::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvPushButton@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvCheckBox::metaObject(void)const " (?metaObject@CvCheckBox@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvCheckBox::qt_metacast(char const *)" (?qt_metacast@CvCheckBox@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvCheckBox::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvCheckBox@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvRadioButton::metaObject(void)const " (?metaObject@CvRadioButton@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvRadioButton::qt_metacast(char const *)" (?qt_metacast@CvRadioButton@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvRadioButton::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvRadioButton@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvWinProperties::metaObject(void)const " (?metaObject@CvWinProperties@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvWinProperties::qt_metacast(char const *)" (?qt_metacast@CvWinProperties@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvWinProperties::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvWinProperties@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CvWindow::metaObject(void)const " (?metaObject@CvWindow@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CvWindow::qt_metacast(char const *)" (?qt_metacast@CvWindow@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CvWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CvWindow@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const CvWindow::staticMetaObject" (?staticMetaObject@CvWindow@@2UQMetaObject@@B)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall ViewPort::metaObject(void)const " (?metaObject@ViewPort@@UBEPBUQMetaObject@@XZ)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall ViewPort::qt_metacast(char const *)" (?qt_metacast@ViewPort@@UAEPAXPBD@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall ViewPort::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@ViewPort@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
window_QT.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const ViewPort::staticMetaObject" (?staticMetaObject@ViewPort@@2UQMetaObject@@B)
C:\OpenCV2.2\Build_QT\bin\Debug\opencv_highgui220d.dll : fatal error LNK1120: 31 unresolved externals
========== Build: 1 succeeded, 1 failed, 8 up-to-date, 0 skipped ==========

5 Answers 5

6

The Qt MOC (meta-object compiler) is not being run on your Qt class files.

Since you're building from the OpenCV release, I'm assuming that the UI classes already have a Q_OBJECT line within the class declaration.

To generate a .vcproj file that has the necessary build instructions to run MOC, run this command:

qmake -tp vc -r <yourProFile.pro>

If that doesn't work, right-click one of the .h files that contains a Qt class. Under Properties->Custom Build Step->General, you should see something like:

Command Line "$(QTDIR)\bin\moc.exe" -I".\GeneratedFiles\." -I"$(QTDIR)\include\." -I".\GeneratedFiles\$(ConfigurationName)\." -I"$(QTDIR)\include\QtCore\." -I"$(QTDIR)\include\QtGui\." .\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp" "-fstdafx.h" "-f[YourQtFile.h]"
Description Moc'ing $(InputFileName)...
Outputs ".\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp"
Additional Dependencies "$(QTDIR)\bin\moc.exe";$(InputPath)

Hope this helps.

3
  • I tried the command: qmake -tp vc -r opencv_highgui.vcxproj. However, it reports: opencv_highgui.vcxproj:5: Parse Error ('<Configuration>Debug</Configuration>') Error processing project file: opencv_highgui.vcxproj. It seems qmake does NOT support VS2010?
    – MikimotoH
    Jul 1, 2011 at 5:53
  • Done. After I tried the below command to manually "moc" out window_QT.h with Q_OBJECT, this project is built successfully. Command: moc -I"%QTDIR%\include" -I"%QTDIR%\include\QtCore" -I"%QTDIR%\include\QtGui" -omoc_window_QT.cpp window_QT.h
    – MikimotoH
    Jul 1, 2011 at 6:27
  • When you configure Qt manually, win32-msvc2008 is the 'highest' Visual Studio designator they have. I don't know whether VS2010 differs significantly. (I'm on VS2005.) Glad to hear that your problem was solved.
    – Gnawme
    Jul 1, 2011 at 17:05
0
  1. Add directory C:/QtSDK/Desktop/Qt/4.7.3/msvc2008/lib in Additional Library Directories in Linker Property pages

if you are building with vs2010, i suggest you should add dir with libraries compiled with vs2010... your path is probably refer to vs2008 libs.

2
  • I installed the lastest version of QT SDK, and there is no directory named as msvc2010 under this SDK dir.
    – MikimotoH
    Jun 29, 2011 at 15:11
  • is there any other lib files around? I use qt in qt libraries edition,it has another folder structure.. QMetaObject should be in QtCore4.lib and QtCored4.lib
    – Raiv
    Jun 29, 2011 at 15:23
0

This may help someone:

I encountered this error for a new QOBJECT class I made, and it went away after re-running qmake (Build->Run qmake), then rebuilding.

0

though very late response.... I followed the following steps to get rid of above error:

1) Install OpenSource QT Version or QT for Visual studio version. 2) Install visual studio QT addin in Visual Studio [http://qt.nokia.com/downloads/visual-studio-add-in]. 3) create a project using QT and not as a normal visual studio project. Created QT project will automatically become a visual studio project.

FOR existign QT projects..... 1) Open the project from QT menu and not from the File menu of Visual Studio.

Hope this helpe...............I consumed 2 days to get this working.

0

I realize this question/answer is a bit old, but I ran into this as an exact hit for the same issue, so it's still around. We had an open source project that was a bit of a hydra; it used both WxWidgets AND QT5 (Open Source). Yet, nothing in it actually ran the moc compiler, so I got the subject error when I attempted to use some thread classes.

IF you install Qt5, this step 'might' be done for you, but I'd tried that and hadn't gotten past the link step. The source I was working with thoughtfully bundled everything with a batch file that would correctly run cmake - just didn't include the MOC. So, to retrofit what I had to do was the following.

The fix for me was:

  1. Manually create an environment var called QtDir, and set it to the SDK that came with the open source project, or whatever Qt library you download.
  2. Go to Visual Studio 2019, right click on the .H file. Go to Properties. You'll see something like this. What wasn't obvious to me at first was that "Item Type" can be clicked on.

Project File properties.

  1. Change to "Custom build step".

enter image description here

  1. Go to the Project, and enter a "Custom Build Step" for all configurations if you've got more than one file, which is likely, or edit the build step right from that file.

Some nice macros which may be new: $(GeneratedFileExtension) which is .g.cpp; but in practice, it seemed to be empty when the project built. So I typed in .g.cpp manually. %(Identity) %(Filename) but use %(FullFilePath)

@Gnawme's answer got me part of the way there, but $(InputFileName) didn't work for VS2019. (Most likely MS moved forward ...). Also, The moc compliler didn't seem to take -f"filename.h" it just wanted filename.h

So what my final "Command Line" for the custom build step was:

$(QTDIR)bin\moc.exe -I".\GeneratedFiles\." -I"$(QTDIR)\include\." -I".\GeneratedFiles\$(ConfigurationName)\." -I"$(QTDIR)\include\QtCore\." -I"$(QTDIR)\include\QtGui\." -o".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).g.cpp" "%(FullPath)"

Note if you put quotes around the executable path, you'll get a weird error about invalid characters in the path.

Then you want a description of:

Moc'ing %(FileName) to produce %(Filename).g.cpp

Outputs will be:

.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).g.cpp

Now ... a tricksy thing I tried; Change "Add Outputs to Item Type" and then "C/C++ Compiler" from the drop down. This means the generated files will automatically be compiled, without having to 'add' them to the project.

.. except it didn't work. Sort of bone headed, but it only has to be done once. The docs actually mention this:

If you want the build system to operate on an output file generated by the custom build tool, you must manually add it to the project. The custom build tool will update the file during the build.

Ah well! It's easy though, the first time you do the build, it'll fail with a linker error, which is your clue to go find the .g.cpp file and add it. I added the ".g" so that it's obvious this is a generated file; if you try to edit file there are copious warnings. Still, that way you could .gitnore stuff, etc.

The custom step should look like this:

Final Project custom settings

Now you even have a menu item for compiling that specific .h file which in practice seems ... weird. .h files aren't compiled, they are included. Except with Qt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.