Results 1 to 3 of 3

Thread: using moc with cmake

  1. #1
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default using moc with cmake

    I am creating a project that uses Qt 4.3.3 and Qwt 5.1.1 (http://qwt.sourceforge.net/).
    I am using CMake version 2.4 to generate the project files for MS Visual Studio 2005 Pro (on Windows XP Pro)

    I create a derived class ScatterPlot that inherits from QwtPlot and QObject.
    I run into a linking error when I use the Q_OBJECT macro in my derived class as shown in attached files.

    The moc_scatterplot.cxx and the moc_scatterplot.obj files are created during compilation.
    If I remove the Q_OBJECT macro from the header, it compiles fine.

    What am I missing? Thanks, Isaac

    ************************************************** ************************************************** ************************
    Build Output
    ************************************************** ************************************************** ************************
    1>------ Build started: Project: ThreeSpaceViewer, Configuration: Debug Win32 ------
    1>Generating moc_scatterplot.cxx
    1>Compiling...
    1>moc_scatterplot.cxx
    1>main.cpp
    1>Generating Code...
    1>Linking...
    1>moc_scatterplot.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B)
    1>Debug\ThreeSpaceViewer.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Isaac\Fars_Isaac\qwt2qt\bin\ThreeSpaceViewer.di r\Debug\BuildLog.htm"
    1>ThreeSpaceViewer - 2 error(s), 0 warning(s)
    2>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------
    2>Project not selected to build for this solution configuration
    ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 1 skipped ==========
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using moc with cmake

    Do you link your application with Qwt?

  3. #3
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using moc with cmake

    Sorry, I forget the most important file.
    I did link with Qwt.
    Here is my CMakeLists.txt:

    # set project's name
    PROJECT( ThreeSpaceViewer )

    OPTION(MYPROJECT_DEBUG
    "Build the project using debugging code"
    ON)

    # this command finds Qt4 libraries and sets all required variables
    # note that it's Qt4, not QT4 or qt4

    FIND_PACKAGE(Qt4)
    IF(QT4_FOUND)
    # (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 )
    # that contains a path to CMake script)
    INCLUDE( ${QT_USE_FILE} )
    ELSE(QT4_FOUND)
    MESSAGE(FATAL_ERROR
    "Cannot build without Qt4. Please set Qt4_DIR.")
    ENDIF(QT4_FOUND)


    SET(QWT_FOUND "NO")

    IF(QT4_FOUND)
    FIND_PATH(
    QWT_INCLUDE_DIR qwt.h
    C:/Qt
    C:/Qt/Qwt
    C:/Qt/Qwt/src
    )

    SET(QWT_DEBUG_NAMES qwtd5 )
    SET(QWT_RELEASE_NAMES qwtr5 )

    FIND_LIBRARY( QWT_DEBUG_LIBRARY
    NAMES ${QWT_DEBUG_NAMES}
    PATHS /Qt /Qt/Qwt /Qt/Qwt/lib
    )

    FIND_LIBRARY( QWT_RELEASE_LIBRARY
    NAMES ${QWT_RELEASE_NAMES}
    PATHS /Qt /Qt/Qwt /Qt/Qwt/lib
    )

    IF (QWT_DEBUG_LIBRARY OR QWT_RELEASE_LIBRARY)
    IF (MYPROJECT_DEBUG)
    SET(QWT_LIBRARIES ${QWT_DEBUG_LIBRARY})
    SET(QWT_FOUND "YES")
    ELSE (MYPROJECT_DEBUG)
    SET(QWT_LIBRARIES ${QWT_RELEASE_LIBRARY})
    SET(QWT_FOUND "YES")
    ENDIF (MYPROJECT_DEBUG)
    ENDIF (QWT_DEBUG_LIBRARY OR QWT_RELEASE_LIBRARY)

    ENDIF(QT4_FOUND)

    INCLUDE_DIRECTORIES( ${QWT_INCLUDE_DIR} )
    INCLUDE_DIRECTORIES( ${ThreeSpaceViewer_SOURCE_DIR} )
    INCLUDE_DIRECTORIES( ${ThreeSpaceViewer_BINARY_DIR} )

    SET( MY_SRCS
    main.cpp
    )

    SET( MY_HDRS
    scatterplot.h
    )

    # and finally this will run moc:
    QT4_WRAP_CPP( MY_MOC_SRCS ${MY_HDRS} )

    ADD_EXECUTABLE( ThreeSpaceViewer main.cpp scatterplot.h ${MY_MOC_SRCS} )


    TARGET_LINK_LIBRARIES( ThreeSpaceViewer
    ${LINK_FLAGS}
    ${QWT_LIBRARIES}
    ${QT_LIBRARIES}
    )

Similar Threads

  1. Invoking MOC w/MSVS + Qt Visual Integration
    By WinchellChung in forum Newbie
    Replies: 4
    Last Post: 10th August 2010, 22:56
  2. CMake Windows console issue
    By IndigoJo in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2008, 22:12
  3. moc with same file names?
    By cjhuitt in forum Qt Programming
    Replies: 9
    Last Post: 27th April 2007, 20:36
  4. moc related errors
    By kiransu123 in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 09:58
  5. CMake and pthreads
    By Matt Smith in forum General Discussion
    Replies: 5
    Last Post: 3rd September 2006, 20:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.