Qt 4.8.4 giving error in debug mode compilation - qt

I have installed Qt 4.8.4 for Visual Studio 2010.
qt-win-opensource-4.8.4-vs2010.exe
http://download.qt-project.org/archive/qt/4.8/4.8.4/
Qt project file:
LIBS += -lqaxserver \
-lqaxcontainer
In my Qt GUI application I am using QAxobject to access ms-excel.
When I compile my project in release mode, I do not get any error. And GUI is running as expected. I am able to generate excel files using QAxObject objects.
But I am getting the following 3 errors when doing a debug build:
file not found: qaxcontainer.lib(qaxbase.obj)
file not found: qaxcontainer.lib(qaxobject.obj)
file not found: qaxcontainer.lib(qaxtypes.obj)
Why does this happen only in debug builds? How do I solve it?
Edit :----
I commented LIBS & added CONFIG. Still no change release mode is compiling debug is giving error.
#LIBS += -lqaxserver \
# -lqaxcontainer
CONFIG += qaxserver
CONFIG += qaxcontainer
Now i am getting seven errors :----
AxServerd.lib(qaxtypes.obj) : error LNK2005: "class QColor __cdecl OLEColorToQColor(unsigned int)" (?OLEColorToQColor##YA?AVQColor##I#Z) already defined in QAxContainerd.lib(qaxtypes.obj)
QAxServerd.lib(qaxtypes.obj) : error LNK2005: "bool __cdecl QVariantToVARIANT(class QVariant const &,struct tagVARIANT &,class QByteArray const &,bool)" (?QVariantToVARIANT##YA_NABVQVariant##AAUtagVARIANT##ABVQByteArray##_N#Z) already defined in QAxContainerd.lib(qaxtypes.obj)
QAxServerd.lib(qaxtypes.obj) : error LNK2005: "bool __cdecl QVariantToVoidStar(class QVariant const &,void *,class QByteArray const &,unsigned int)" (?QVariantToVoidStar##YA_NABVQVariant##PAXABVQByteArray##I#Z) already defined in QAxContainerd.lib(qaxtypes.obj)
QAxServerd.lib(qaxtypes.obj) : error LNK2005: "class QVariant __cdecl VARIANTToQVariant(struct tagVARIANT const &,class QByteArray const &,unsigned int)" (?VARIANTToQVariant##YA?AVQVariant##ABUtagVARIANT##ABVQByteArray##I#Z) already defined in QAxContainerd.lib(qaxtypes.obj)
QAxServerd.lib(qaxtypes.obj) : error LNK2005: "void __cdecl clearVARIANT(struct tagVARIANT *)" (?clearVARIANT##YAXPAUtagVARIANT###Z) already defined in QAxContainerd.lib(qaxtypes.obj)
QAxServerd.lib(qaxserver.obj) : error LNK2019: unresolved external symbol "class QAxFactory * __cdecl qax_instantiate(void)" (?qax_instantiate##YAPAVQAxFactory##XZ) referenced in function "class QAxFactory * __cdecl qAxFactory(void)" (?qAxFactory##YAPAVQAxFactory##XZ)
debug\geny.exe : fatal error LNK1120: 1 unresolved externals
link /LIBPATH:"c:\Qt\4.8.4\lib" /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /MANIFEST /MANIFESTFILE:"debug\geny.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /OUT:debug\geny.exe #C:\Users\dguleria\AppData\Local\Temp\geny.exe.17776.15.jom
C:\QtSDK\QtCreator\bin\jom.exe -f Makefile.Debug

That's because the libraries are named differently in the debug version. You shouldn't use LIBS for Qt libraries. You should be telling qmake to figure out the link options by doing:
CONFIG += qaxcontainer
This is documented here:
http://qt-project.org/doc/qt-4.8/activeqt-container.html

Related

QVTKWidget error when linking Qt with VTK

I'm having the famous linking error when trying to combine Qt and VTK. I've done all the steps of installing Qt with VTK correctly so I don't know what could possibly be wrong.
I'm using windows 8 with Qt5 and VTK 6.3 on visual studio.
Here is the error I get:
Drawing.obj : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: __thiscall QVTKWidget::QVTKWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QVTKWidget##QAE#PAVQWidget##V?$QFlags#W4WindowType#Qt#####Z) référencé dans la fonction "public: __thiscall Drawing::Drawing(void)" (??0Drawing##QAE#XZ)
1>Drawing.obj : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: virtual __thiscall QVTKWidget::~QVTKWidget(void)" (__imp_??1QVTKWidget##UAE#XZ) référencé dans la fonction "public: __thiscall Drawing::~Drawing(void)" (??1Drawing##QAE#XZ)
And here is the code I use:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QVtk w;
w.show();
//start();
return a.exec();
}
I followed everything that was written here: Combining Qt 5.4.1 with vtk 6.2.0 (using CMake GUI 3.2.1) on windows but somehow I get this error.
Also, I've added: $(QTDIR)\lib to my additional libraries $(QTDIR)\include to my "other include directories" and the followings to my additional dependencies.
qtmaind.lib
C:\Users\Lonni\VTK\Build2012Qt\lib\MinSizeRel\QVTKWidgetPlugin.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Locationd.lib
Qt5Multimediad.lib
Qt5MultimediaWidgetsd.lib
Qt5Testd.lib
Qt5AxContainerd.lib
Qt5AxBased.lib
Qt5OpenGLd.lib
opengl32.lib
glu32.lib
Qt5Sensorsd.lib
Qt5Svgd.lib
Qt5Widgetsd.lib
EDIT:
I did not use CMake for the project as I have issues when using Cmake even with the small example provided on the wiki which gives the following error with the following CMakeLists.txt. NB: I use Visual Studio as a generator.
CMakeLists:
cmake_minimum_required(VERSION 2.8)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif()
PROJECT(RenderWindowNoUiFile)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB UI_FILES *.ui)
file(GLOB QT_WRAP *.h)
file(GLOB CXX_FILES *.cxx)
if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_ui(UISrcs ${UI_FILES} )
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(RenderWindowNoUiFile MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP})
qt5_use_modules(RenderWindowNoUiFile Core Gui)
target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
else()
QT4_WRAP_UI(UISrcs ${UI_FILES})
QT4_WRAP_CPP(MOCSrcs ${QT_WRAP})
add_executable(RenderWindowNoUiFile MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs})
if(VTK_LIBRARIES)
if(${VTK_VERSION} VERSION_LESS "6")
target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES} QVTK)
else()
target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
endif()
else()
target_link_libraries(RenderWindowNoUiFile vtkHybrid QVTK vtkViews ${QT_LIBRARIES})
endif()
endif()
Error:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.2/Modules/FindQt4.cmake:1326 (message):
Found unsuitable Qt version "" from NOTFOUND, this code requires Qt 4.x
Call Stack (most recent call first):
CMakeLists.txt:18 (find_package)

qt odbc plugin build unsuccessful

I developed an application along the lines of the SQL Browser example provided with QT in the Demos and Examples section. My development machine is Windows XP (visual studio compiler was used) and the application works well on it. It is able to connect to an external database (MySQL), and I am able browse through tables. I used the QODBC driver for connections. However when I deploy the executable (with all required .dll files) in another computer without QT, it says that I need to provide for the database drivers. I read the documentation and realized that I need to build a PlugIn for QODBC drivers.
First I looked at an example Plugin (Echo Plugin Example) given at http://doc.qt.digia.com/4.6/tools-echoplugin.html. Then I followed the instructions in http://doc.qt.digia.com/4.6/sql-driver.html#qodbc.
cd %QTDIR%\src\plugins\sqldrivers\odbc
qmake odbc.pro
nmake
The above commands built qsqlodbc4.dll. However, I am not successful in developing a Plugin for my application. Here are my steps, and the compilation output:
Created project odbcplugin.pro (see script below) under directory /odbcpluginTest
TEMPLATE = subdirs
SUBDIRS = sqlbrowser \
odbc
CONFIG += release
# install
target.path = $$PWD
sources.path = $$PWD
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS
INSTALLS += target sources
Created subdirectories: /odbc, /sqlbrowser, /plugins
Inside the directroy /odbcpluginTest /odbc/
(i). Copied odbc.pro and suitably modified the paths and file names (for example, a file originally named as main.cpp has been renamed as mainODBC.cpp to avoid confusing with the file named main.cpp inside /sqlbrowser). See the scripts below:
TEMPLATE = lib
INCLUDEPATH += ../sqlbrowser
SOURCES = mainODBC.cpp
TARGET = qsqlodbc
DESTDIR = ../plugins
CONFIG += release
include(qsql_odbc.pri)
include(qsqldriverbase.pri)
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS
INSTALLS += target sources
(ii). The file odbcinterface.h that describes the plugin interface is included as a header in odbc.pro. However, it is actually placed inside the directory /sqlbrowser. Hence, the line INCLUDEPATH += ../sqlbrowser is included in the above script.
(iii). Also, copied all related project files (qsql_odbc.pri, qsqldriverbase.pri, qpluginbase.pri, qt_targets.pri). Suitably modified the paths in all project files (there may be mistakes in here).
(iv). The header (qsql_odbc.h) and source (qsql_odbc.cpp) files of qsql_odbc.pri have also been copied.
Inside the directory /odbcpluginTest /sqlbrowser/
(i). Copied sqlbrowser.pro and all related files.
(ii). Created the header file odbcinterface.h that describes the plugin interface (see below) and added it to the HEADERS in sqlbrowser.pro.
#ifndef ODBCINTERFACE_H
#define ODBCINTERFACE_H
#include <QString>
#include <QtSql/qsqldriver.h>
class OdbcInterface
{
public:
virtual ~OdbcInterface() {}
virtual QSqlDriver* create(const QString &) = 0;
virtual QStringList keys() const = 0;
};
QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(OdbcInterface,
"developed similar to com.trolltech.Plugin.EchoInterface/1.0");
QT_END_NAMESPACE
#endif // ODBCINTERFACE_H
iii. Also, modified the browser.h file by adding the lines
#include "odbcinterface.h"
private:
bool loadPlugin();
OdbcInterface *odbcInterface;
Public:
void TestCase1();
iv. Also, modified the browser.cpp file by adding the function definitions:
bool Browser::loadPlugin()
{
QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
pluginsDir.cdUp();
pluginsDir.cdUp();
#endif
pluginsDir.cd("plugins");
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
QObject *pluginI = pluginLoader.instance();
if (pluginI) {
odbcInterface = qobject_cast<OdbcInterface *>(pluginI);
if (odbcInterface)
return true;
}
}
return false;
}
void Browser::TestCase1()
{
loadPlugin();
QStringList list;
list = odbcInterface->keys();
QMessageBox msgBox;
if(list.length() >0)
{
msgBox.setText("Test1 success");
}
else
{
msgBox.setText("Test1 failure");
}
msgBox.exec();
}
Testing:
In browser.cpp file, the constructor Browser::Browser(QWidget *parent) was modified by appending a call to void Browser::TestCase1()
Compile Output:
15:09:18: Running build steps for project odbcplugin...
15:09:18: Configuration unchanged, skipping qmake step.
15:09:18: Starting: "C:\QtSDK\QtCreator\bin\jom.exe"
cd sqlbrowser\ && C:\QtSDK\QtCreator\bin\jom.exe -nologo -j 2 -f Makefile
C:\QtSDK\QtCreator\bin\jom.exe -nologo -j 2 -f Makefile.Debug
cd odbc\ && C:\QtSDK\QtCreator\bin\jom.exe -nologo -j 2 -f Makefile
C:\QtSDK\QtCreator\bin\jom.exe -nologo -j 2 -f Makefile.Release
link /LIBPATH:"c:\QtSDK\Desktop\Qt\4.8.1\msvc2010\lib" /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /DLL /MANIFEST /MANIFESTFILE:"release\qsqlodbc.intermediate.manifest" /VERSION:4.81 /OUT:..\plugins\qsqlodbc4.dll #C:\DOCUME~1\SHAINE~1\LOCALS~1\Temp\qsqlodbc4.dll.5076.0.jom
Creating library ..\plugins\qsqlodbc4.lib and object ..\plugins\qsqlodbc4.exp
mainODBC.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QODBCDriverPlugin::metaObject(void)const " (?metaObject#QODBCDriverPlugin##UBEPBUQMetaObject##XZ)
mainODBC.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QODBCDriverPlugin::qt_metacast(char const *)" (?qt_metacast#QODBCDriverPlugin##UAEPAXPBD#Z)
mainODBC.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QODBCDriverPlugin::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#QODBCDriverPlugin##UAEHW4Call#QMetaObject##HPAPAX#Z)
..\plugins\qsqlodbc4.dll : fatal error LNK1120: 3 unresolved externals
jom 1.0.6 - empower your cores
command failed with exit code 1120
command failed with exit code 2
command failed with exit code 2
15:09:19: The process "C:\QtSDK\QtCreator\bin\jom.exe" exited with code 2.
Error while building project odbcplugin (target: Desktop)
When executing build step 'Make'

OpenCV 2.4.6 with QT 5.1.0 Errors

I am trying to get OpenCv2.4.6 to work with QT5.1.0
I've followed this Guide so far Qt creator 5.0.1 with OpenCv 2.3.4 on windows
Unfortunatly after finishing trying out the sample Application(Display an Image using OpenCv in the QtCreator I get these Errors:
[Project-Path]\main.o:-1: In function `main':
[Project-Path]\main.cpp:8: error: undefined reference to `cv::imread(std::string const&, int)'
[Project-Path]\main.cpp:9: error: undefined reference to `cv::namedWindow(std::string const&, int)'
[Project-Path]\main.cpp:10: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
[Project-Path]\main.cpp:10: error: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
[Project-Path]\main.cpp:11: error: undefined reference to `cv::waitKey(int)'
[Project Build Path Desktop Debug]\debug\main.o:-1: In function `ZN2cv3MatD1Ev':
[OpenCV/Install/include]\opencv2\core\mat.hpp:278: error: undefined reference to `cv::fastFree(void*)'
[Project Build Path Desktop Debug]\debug\main.o:-1: In function `ZN2cv3Mat7releaseEv':
[OpenCV/Install/include]\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()'
collect2.exe:-1: error: error: ld returned 1 exit status
the "[]" Paths are my formatting and supposed to help keep track .
main.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
// read an image
Mat image = imread("img.jpg");
namedWindow("My Image");
imshow("My Image", image);
waitKey(5000);
return 1;
}
myFirstOpenCVProject.pro
QT += core
QT -= gui
TARGET = myFirstOpenCVProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/qt/OpenCV246_bin/install/include
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_core246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_highgui246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_imgproc246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_features2d246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_calib3d246.dll
Can you help me resolve this?
I can't find any solutions that apply to my case ...
-L is to add directories to the search path. The actual libs are added via -l. The correct line would be:
LIBS += -LC:/qt/OpenCV246_bin/install/lib -llopencv_core246 -llopencv_highgui246 ...
I think you are missing the static libs of opencv:
opencv_core246.lib
opencv_highgui246.lib
opencv_video246.lib
opencv_ml26d.lib
opencv_legacy246.lib
opencv_imgproc246.lib
opencv_whatever.lib
Don t know the pro commands very well. Maybe something like:
LIBS += -Lc:/blabla/opencv_imgproc246.lib

Unresolved symbols QMetaObject when building OpenCV with QT support

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_OPENGL3. 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 ==========
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.
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.
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.
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.
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:
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.
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.
Change to "Custom build step".
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:
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.

How does one resolve link error with Qt?

I'm new to Qt, and trying to compile and link a simple "Hello, World" program using Microsoft's "CL.exe". Any advice on how to do this?
The program is:
#include <QtGui>
int main ( int argc, char * argv [] )
{
QApplication app ( argc, argv ) ;
QLabel label ( "Hello, world!" ) ;
label.show() ;
return app.exec() ;
}
I compile and link with:
C:\PROGRA~1\MICROS~1.0\VC\bin\cl.EXE -nologo -Zm200 -Zc:wchar_t- -O2 -MD ^
-W3 -w34100 -w34189 -DUNICODE ^
-DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB ^
-DQT_THREAD_SUPPORT -DQT_NO_DYNAMIC_CAST ^
-I"C:\Qt\2010.05\qt\include\QtCore" ^
-I"C:\Qt\2010.05\qt\include\QtGui" ^
-I"C:\Qt\2010.05\qt\include" ^
-I"." ^
-I"C:\Qt\2010.05\qt\include\ActiveQt" ^
-I"release" ^
-I"C:\Qt\2010.05\qt\mkspecs\win32-msvc2008" ^
-I"C:\Progra~1\MICROS~1.0\VC\include" ^
Hello.cpp ^
/link /LIBPATH:"C:\Qt\2010.05\qt\lib" ^
/LIBPATH:"C:\Progra~1\MICROS~1.0\VC\lib" ^
/LIBPATH:"C:\Progra~1\MID05A~1\VC\PLATFO~1\Lib"
My linker errors include:
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplicatio
n##UAE#XZ) referenced in function _main
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: virtual __thiscall QLabel::~QLabel(void)" (__imp_??1QLabel##UAE#XZ) referen
ced in function _main
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: static int __cdecl QApplication::exec(void)" (__imp_?exec#QApplication##SAH
XZ) referenced in function _main
Hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pub
lic: void __thiscall QWidget::show(void)" (__imp_?show#QWidget##QAEXXZ) referenc
ed in function _main
.
.
.
My Hello.pro file contains:
######################################################################
# Automatically generated by qmake (2.01a) Mon Dec 13 15:58:13 2010
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += Hello.cpp
You should be linking against QtCore and QtGui libraries but you don't. What does your .pro file look like?
Edited to add after the .pro file was posted: Your .pro file looks all right. You're not overwriting the QT variable which by default includes core gui, which should result in QtCode and QtGui being linked to. It's also evident by the fact that both QtCore and QtGui are present in your include paths.
I haven't used cl.exe with Qt but you could try adding LIBS += -lQtCore -lQtGui to force linking to QtCore and QtGui. (There's probably a more elegant fix though.)
Your PATH should include the qt/bin directory. In a Visual Studio Command Prompt you should do a "qmake hello.pro" which creates three makefiles, and then "nmake". If you want to use vcxproj files, you should change your TEMPLATE to vcapp.
trying to compile and link a simple
"Hello, World" program using
Microsoft's "CL.exe"
Hey i think there are easier ways of getting qt applications compiled on visual studio. Instead of struggling with commandline options why not install the qt visual studio addin that makes compiling projects soooooooo easy? Just a suggestion :)

Resources