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>).&nbsp; <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.&nbsp; <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?&nbsp; Thanks,&nbsp; Isaac<br><br><br>
****************************************************************************************************************************<br>Build Output<br>
****************************************************************************************************************************<br>1&gt;------ Build started: Project: ThreeSpaceViewer, Configuration: Debug Win32 ------<br>1&gt;Generating moc_scatterplot.cxx<br>
1&gt;Compiling...<br>1&gt;moc_scatterplot.cxx<br>1&gt;main.cpp<br>1&gt;Generating Code...<br>1&gt;Linking...<br>1&gt;moc_scatterplot.obj : error LNK2001: unresolved external symbol &quot;public: static struct QMetaObject const QwtPlot::staticMetaObject&quot; (?staticMetaObject@QwtPlot@@2UQMetaObject@@B)<br>
1&gt;Debug\ThreeSpaceViewer.exe : fatal error LNK1120: 1 unresolved externals<br>1&gt;Build log was saved at &quot;file://c:\Isaac\Fars_Isaac\qwt2qt\bin\ThreeSpaceViewer.dir\Debug\BuildLog.htm&quot;<br>1&gt;ThreeSpaceViewer - 2 error(s), 0 warning(s)<br>
2&gt;------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------<br>2&gt;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 &lt;qwt_plot.h&gt;<br><br>class ScatterPlot : public QwtPlot<br>{<br>&nbsp; Q_OBJECT<br>public:<br>&nbsp;&nbsp;&nbsp; ScatterPlot(QWidget *parent = NULL){};<br><br>};<br><br><br>
****************************************************************************************************************************<br>main.cpp<br>
****************************************************************************************************************************<br>#include &lt;QtGui/QApplication&gt;<br>#include &lt;qwt_plot.h&gt;<br>#include &quot;scatterplot.h&quot;<br>
<br>int main(int argc, char *argv[])<br>{<br>&nbsp;&nbsp;&nbsp; QApplication app(argc, argv);<br><br>&nbsp;&nbsp;&nbsp; ScatterPlot *plot = new ScatterPlot();<br><br>&nbsp;&nbsp;&nbsp; return app.exec();<br>}<br><br>****************************************************************************************************************************<br>
CMakeLists.txt<br>****************************************************************************************************************************<br># set project&#39;s name<br>PROJECT( ThreeSpaceViewer )<br><br>OPTION(MYPROJECT_DEBUG<br>
&nbsp; &quot;Build the project using debugging code&quot;<br>&nbsp; ON)<br>&nbsp; <br>IF(MYPROJECT_DEBUG)<br>&nbsp; SET(CMAKE_BUILD_TYPE debug)<br>&nbsp; SET(CMAKE_CONFIGURATION_TYPES debug)<br>ELSE(MYPROJECT_DEBUG)<br>&nbsp; SET(CMAKE_BUILD_TYPE release)<br>
&nbsp; 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&#39;s Qt4, not QT4 or qt4<br><br>&nbsp; FIND_PACKAGE(Qt4)<br>&nbsp; IF(QT4_FOUND)<br>
&nbsp;&nbsp;&nbsp; # (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) <br>&nbsp;&nbsp;&nbsp; # that contains a path to CMake script)<br>&nbsp;&nbsp;&nbsp; INCLUDE( ${QT_USE_FILE} )<br>&nbsp; ELSE(QT4_FOUND)<br>&nbsp;&nbsp;&nbsp; MESSAGE(FATAL_ERROR<br>&nbsp;&nbsp;&nbsp; &quot;Cannot build without Qt4.&nbsp; Please set Qt4_DIR.&quot;)<br>
&nbsp; ENDIF(QT4_FOUND)<br>&nbsp; <br>&nbsp; <br>&nbsp;SET(QWT_FOUND &quot;NO&quot;)<br><br>&nbsp;IF(QT4_FOUND)<br>&nbsp;&nbsp;&nbsp;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; SET(QWT_FOUND &quot;YES&quot;)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ELSE (MYPROJECT_DEBUG)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SET(QWT_LIBRARIES ${QWT_RELEASE_LIBRARY})<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SET(QWT_FOUND &quot;YES&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ENDIF (MYPROJECT_DEBUG)<br>&nbsp;&nbsp;&nbsp; ENDIF (QWT_DEBUG_LIBRARY OR QWT_RELEASE_LIBRARY)<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;ENDIF(QT4_FOUND)<br>&nbsp; <br>&nbsp;INCLUDE_DIRECTORIES( ${QWT_INCLUDE_DIR} )<br>&nbsp;INCLUDE_DIRECTORIES( ${ThreeSpaceViewer_SOURCE_DIR} )<br>&nbsp;INCLUDE_DIRECTORIES( ${ThreeSpaceViewer_BINARY_DIR} )<br><br>SET( MY_SRCS<br>&nbsp;&nbsp;&nbsp; main.cpp<br>
)<br><br>SET( MY_HDRS<br>&nbsp;&nbsp;&nbsp; scatterplot.h<br>)<br><br># and finally this will run moc:<br>QT4_WRAP_CPP( MY_MOC_SRCS&nbsp; ${MY_HDRS} )<br><br>ADD_EXECUTABLE( ThreeSpaceViewer main.cpp scatterplot.h ${MY_MOC_SRCS} )<br>&nbsp;<br><br>
TARGET_LINK_LIBRARIES( ThreeSpaceViewer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${LINK_FLAGS} <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ${QWT_LIBRARIES} <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ${QT_LIBRARIES}<br>)<br>**************************************************************************************************************<br>