Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Porting Qt example to CMake (e.g. openglunderqml)
QtWS25 Last Chance

[Solved] Porting Qt example to CMake (e.g. openglunderqml)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martinoso
    wrote on last edited by
    #1

    Hi

    I would like to integrate qml into my CMake project. For that I first tried to port this example:

    @$HOME/Qt/Examples/Qt-5.3/quick/scenegraph/openglunderqml@

    from QMake to CMake. The QMake project compiles fine.

    My CMakeLists.txt is

    @
    cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

    project(openglunderqml)

    find_package(Qt5Quick REQUIRED)
    find_package(Qt5Qml REQUIRED)
    find_package(OpenGL REQUIRED)

    qt5_add_resources(QT_QRC_SRCS openglunderqml.qrc)

    The headers, qml and qrc files are added so they show up in Qt Creator.

    add_executable(openglunderqml
    main.cpp
    main.qml
    openglunderqml.qrc
    squircle.cpp
    squircle.h
    ${QT_QRC_SRCS}
    )
    target_link_libraries(openglunderqml Qt5::Qml Qt5::Quick ${OPENGL_LIBRARIES})
    @

    When I build I get following error

    @
    Linking CXX executable openglunderqml
    Undefined symbols for architecture x86_64:
    "Squircle::qt_metacall(QMetaObject::Call, int, void**)", referenced from:
    vtable for QQmlPrivate::QQmlElement<Squircle> in main.cpp.o
    "Squircle::qt_metacast(char const*)", referenced from:
    vtable for QQmlPrivate::QQmlElement<Squircle> in main.cpp.o
    "Squircle::staticMetaObject", referenced from:
    int qmlRegisterType<Squircle>(char const*, int, int, char const*) in main.cpp.o
    QtPrivate::MetaObjectForType<Squircle*, true>::value() in main.cpp.o
    QMetaTypeIdQObject<Squircle*, true>::qt_metatype_id() in main.cpp.o
    "Squircle::tChanged()", referenced from:
    Squircle::setT(double) in squircle.cpp.o
    "Squircle::metaObject() const", referenced from:
    vtable for QQmlPrivate::QQmlElement<Squircle> in main.cpp.o
    "typeinfo for Squircle", referenced from:
    typeinfo for QQmlPrivate::QQmlElement<Squircle> in main.cpp.o
    "vtable for SquircleRenderer", referenced from:
    SquircleRenderer::~SquircleRenderer() in squircle.cpp.o
    SquircleRenderer::SquircleRenderer() in squircle.cpp.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    "vtable for Squircle", referenced from:
    Squircle::Squircle() in squircle.cpp.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [openglunderqml] Error 1
    make[1]: *** [CMakeFiles/openglunderqml.dir/all] Error 2
    make: *** [all] Error 2
    @

    This problem might be related to http://qt-project.org/forums/viewthread/35646/

    I would like to try the posted solution but I don't know how to translate this from QMake to CMake. What does QMake do with these flags internally and what is the CMake equivalent respectively?

    @
    QMAKE_MACOSX_DEPLOYMENT_TARGET=10.9
    macx:QMAKE_MAC_SDK=macosx10.9
    @

    I am on Mac OS X 10.9.4 (Mavericks) with Qt-5.3.1-0 from the online installer.

    thanks a lot.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I think you need to add QtCore and QtGui module includes to your cmakelists file. And (maybe) include squircle header before the source file.

      Edit: also, I think one needs to explicitly tell CMake to run AUTOMOC.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Martinoso
        wrote on last edited by
        #3

        Great. It works now! I totally forgot about automoc.

        Put this before add_executable
        @
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_INCLUDE_CURRENT_DIR ON)
        @

        Alternatively put this at the end
        @
        set_target_properties(openglunderqml PROPERTIES AUTOMOC ON)
        target_include_directories(openglunderqml PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
        @

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Great, thanks for sharing the solution with us. I actually plan to learn CMake in the coming weeks, so it will come in handy :-)

          (Z(:^

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved