I am creating a project that uses Qt 4.3.3 and Qwt 5.1.1 (<a href="http://qwt.sourceforge.net/">http://qwt.sourceforge.net/</a>). <br>I am using CMake version 2.4 to generate the project files for MS Visual Studio 2005 Pro (on Windows XP Pro)<br>
<br>I create a derived class ScatterPlot that inherits from QwtPlot and QObject. <br>I run into a linking error when I use the Q_OBJECT macro in my derived class as shown below. <br><br>The moc_scatterplot.cxx and the moc_scatterplot.obj files are created during compilation.<br>
If I remove the Q_OBJECT macro from the header, it compiles fine.<br><br>What am I missing? Thanks, Isaac<br><br><br>
****************************************************************************************************************************<br>Build Output<br>
****************************************************************************************************************************<br>1>------ Build started: Project: ThreeSpaceViewer, Configuration: Debug Win32 ------<br>1>Generating moc_scatterplot.cxx<br>
1>Compiling...<br>1>moc_scatterplot.cxx<br>1>main.cpp<br>1>Generating Code...<br>1>Linking...<br>1>moc_scatterplot.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B)<br>
1>Debug\ThreeSpaceViewer.exe : fatal error LNK1120: 1 unresolved externals<br>1>Build log was saved at "file://c:\Isaac\Fars_Isaac\qwt2qt\bin\ThreeSpaceViewer.dir\Debug\BuildLog.htm"<br>1>ThreeSpaceViewer - 2 error(s), 0 warning(s)<br>
2>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------<br>2>Project not selected to build for this solution configuration <br>========== Build: 0 succeeded, 1 failed, 1 up-to-date, 1 skipped ==========<br>
<br>****************************************************************************************************************************<br>scatterplot.h<br>****************************************************************************************************************************<br>
#include <qwt_plot.h><br><br>class ScatterPlot : public QwtPlot<br>{<br> Q_OBJECT<br>public:<br> ScatterPlot(QWidget *parent = NULL){};<br><br>};<br><br><br>
****************************************************************************************************************************<br>main.cpp<br>
****************************************************************************************************************************<br>#include <QtGui/QApplication><br>#include <qwt_plot.h><br>#include "scatterplot.h"<br>
<br>int main(int argc, char *argv[])<br>{<br> QApplication app(argc, argv);<br><br> ScatterPlot *plot = new ScatterPlot();<br><br> return app.exec();<br>}<br><br>****************************************************************************************************************************<br>
CMakeLists.txt<br>****************************************************************************************************************************<br># set project's name<br>PROJECT( ThreeSpaceViewer )<br><br>OPTION(MYPROJECT_DEBUG<br>
"Build the project using debugging code"<br> ON)<br> <br>IF(MYPROJECT_DEBUG)<br> SET(CMAKE_BUILD_TYPE debug)<br> SET(CMAKE_CONFIGURATION_TYPES debug)<br>ELSE(MYPROJECT_DEBUG)<br> SET(CMAKE_BUILD_TYPE release)<br>
SET(CMAKE_CONFIGURATION_TYPES release)<br>ENDIF(MYPROJECT_DEBUG)<br><br># this command finds Qt4 libraries and sets all required variables<br># note that it's Qt4, not QT4 or qt4<br><br> FIND_PACKAGE(Qt4)<br> IF(QT4_FOUND)<br>
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) <br> # that contains a path to CMake script)<br> INCLUDE( ${QT_USE_FILE} )<br> ELSE(QT4_FOUND)<br> MESSAGE(FATAL_ERROR<br> "Cannot build without Qt4. Please set Qt4_DIR.")<br>
ENDIF(QT4_FOUND)<br> <br> <br> SET(QWT_FOUND "NO")<br><br> IF(QT4_FOUND)<br> FIND_PATH( <br> QWT_INCLUDE_DIR qwt.h<br> C:/Qt <br> C:/Qt/Qwt <br> C:/Qt/Qwt/src<br> )<br><br> SET(QWT_DEBUG_NAMES qwtd5 )<br>
SET(QWT_RELEASE_NAMES qwtr5 )<br> <br> FIND_LIBRARY( QWT_DEBUG_LIBRARY<br> NAMES ${QWT_DEBUG_NAMES}<br> PATHS /Qt /Qt/Qwt /Qt/Qwt/lib<br> )<br><br> FIND_LIBRARY( QWT_RELEASE_LIBRARY<br> NAMES ${QWT_RELEASE_NAMES}<br>
PATHS /Qt /Qt/Qwt /Qt/Qwt/lib<br> )<br> <br> IF (QWT_DEBUG_LIBRARY OR QWT_RELEASE_LIBRARY)<br> IF (MYPROJECT_DEBUG)<br> SET(QWT_LIBRARIES ${QWT_DEBUG_LIBRARY})<br> SET(QWT_FOUND "YES")<br>
ELSE (MYPROJECT_DEBUG)<br> SET(QWT_LIBRARIES ${QWT_RELEASE_LIBRARY})<br> SET(QWT_FOUND "YES")<br> ENDIF (MYPROJECT_DEBUG)<br> ENDIF (QWT_DEBUG_LIBRARY OR QWT_RELEASE_LIBRARY)<br>
<br> ENDIF(QT4_FOUND)<br> <br> INCLUDE_DIRECTORIES( ${QWT_INCLUDE_DIR} )<br> INCLUDE_DIRECTORIES( ${ThreeSpaceViewer_SOURCE_DIR} )<br> INCLUDE_DIRECTORIES( ${ThreeSpaceViewer_BINARY_DIR} )<br><br>SET( MY_SRCS<br> main.cpp<br>
)<br><br>SET( MY_HDRS<br> scatterplot.h<br>)<br><br># and finally this will run moc:<br>QT4_WRAP_CPP( MY_MOC_SRCS ${MY_HDRS} )<br><br>ADD_EXECUTABLE( ThreeSpaceViewer main.cpp scatterplot.h ${MY_MOC_SRCS} )<br> <br><br>
TARGET_LINK_LIBRARIES( ThreeSpaceViewer <br> ${LINK_FLAGS} <br> ${QWT_LIBRARIES} <br> ${QT_LIBRARIES}<br>)<br>**************************************************************************************************************<br>