<div dir="ltr">Hello everyone!<br><br>I&#39;m trying to compile a simple application using Qt4 with cmake, but I&#39;m stucked in this error:<br><br>[ 33%] Generating ui_mivgui.h<br>Scanning dependencies of target viewer<br>
[ 66%] Building CXX object CMakeFiles/viewer.dir/main.o<br>[100%] Building CXX object CMakeFiles/viewer.dir/mivgui.o<br>Linking CXX executable viewer<br>CMakeFiles/viewer.dir/mivgui.o: In function `MivGui::MivGui(QWidget*)&#39;:<br>
mivgui.cxx:(.text+0x14e): undefined reference to `vtable for MivGui&#39;<br>mivgui.cxx:(.text+0x158): undefined reference to `vtable for MivGui&#39;<br>CMakeFiles/viewer.dir/mivgui.o: In function `MivGui::MivGui(QWidget*)&#39;:<br>
mivgui.cxx:(.text+0x2c6): undefined reference to `vtable for MivGui&#39;<br>mivgui.cxx:(.text+0x2d0): undefined reference to `vtable for MivGui&#39;<br>CMakeFiles/viewer.dir/mivgui.o: In function `MivGui::tr(char const*, char const*)&#39;:<br>
mivgui.cxx:(.text._ZN6MivGui2trEPKcS1_[MivGui::tr(char const*, char const*)]+0x1e): undefined reference to `MivGui::staticMetaObject&#39;<br>collect2: ld returned 1 exit status<br>make[2]: *** [viewer] Error 1<br>make[1]: *** [CMakeFiles/viewer.dir/all] Error 2<br>
make: *** [all] Error 2<br><br>This is the code I have for mivgui.h:<br><br>#include &quot;ui_mivgui.h&quot;<br><br>class MivGui : public QMainWindow, private Ui::MivGui<br>{<br>&nbsp;&nbsp; Q_OBJECT<br><br>&nbsp;&nbsp; public:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MivGui(QWidget *parent = 0);<br>
<br>&nbsp;&nbsp; private slots:<br>&nbsp;&nbsp;&nbsp; void open();<br>};<br><br>And for the mivgui.cxx:<br><br>#include &lt;QtGui&gt;<br>#include &quot;mivgui.h&quot;<br><br>MivGui::MivGui(QWidget *parent): QMainWindow(parent)<br>{<br>&nbsp;&nbsp;&nbsp; setupUi(this);<br>
<br>&nbsp;&nbsp;&nbsp; QDesktopWidget *desktop = QApplication::desktop();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; int screenWidth, width; <br>&nbsp;&nbsp;&nbsp; int screenHeight, height;<br>&nbsp;&nbsp;&nbsp; int x, y;<br>&nbsp;&nbsp;&nbsp; QSize windowSize;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; screenWidth = desktop-&gt;width(); // get width of screen<br>
&nbsp;&nbsp;&nbsp; screenHeight = desktop-&gt;height(); // get height of screen<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; windowSize = size(); // size of our application window<br>&nbsp;&nbsp;&nbsp; width = windowSize.width(); <br>&nbsp;&nbsp;&nbsp; height = windowSize.height();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // little computations<br>
&nbsp;&nbsp;&nbsp; x = (screenWidth - width) / 2;<br>&nbsp;&nbsp;&nbsp; y = (screenHeight - height) / 2;<br>&nbsp;&nbsp;&nbsp; y -= 50;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // move window to desired coordinates<br>&nbsp;&nbsp;&nbsp; move ( x, y );<br><br>&nbsp;&nbsp;&nbsp; // make connections<br>&nbsp;&nbsp;&nbsp; connect(actionOpen, SIGNAL(triggered()), this, SLOT(open()));<br>
}<br><br>void MivGui::open()<br>{<br>&nbsp;&nbsp;&nbsp; QString fileName = QFileDialog::getOpenFileName(this, tr(&quot;Open File&quot;), QDir::currentPath());<br>}<br><br><br>CMakeLists.txt<br>----------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>SET(SOURCES_CPP<br>&nbsp;main.cxx<br>&nbsp;mivgui.cxx)<br>MESSAGE( STATUS ${SOURCES_CPP} )<br><br>SET(SOURCES_H<br>&nbsp;mivgui.h)<br>MESSAGE( STATUS ${SOURCES_H} )<br><br>SET(SOURCES_UI<br>&nbsp;mivgui.ui)<br>MESSAGE( STATUS ${SOURCES_UI} )<br>
<br>FIND_PACKAGE(Qt4 REQUIRED)<br><br>include(${QT_USE_FILE})<br><br>QT4_WRAP_UI(SOURCES_UI_H ${SOURCES_UI})<br><br>#qt4_automoc(${SOURCES_H})<br><br>INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )<br><br>ADD_EXECUTABLE(viewer ${SOURCES_CPP} ${SOURCES_H} ${SOURCES_UI_H})<br>
<br>TARGET_LINK_LIBRARIES(viewer ${QT_LIBRARIES} ${QT_QTSQL_LIBRARIES})<br><br>----------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>Does anybody know how to solve this problem?<br><br>PS: It works fine with qmake, but I need to use cmake in order to integrate with some ITK functions.<br><br>Thanks,<br>Luis<br></div>