2

I was using an old CMakeLists of a package based on QT4:

cmake_minimum_required(VERSION 2.8.0)
project(pol)

add_compile_options(-std=c++17)
find_package(catkin REQUIRED COMPONENTS qt_build roscpp sensor_msgs cv_bridge image_transport)
find_package(OpenCV REQUIRED)
include_directories(${catkin_INCLUDE_DIRS})

catkin_package()

rosbuild_prepare_qt4(QtCore QtGui) # Add the appropriate components to the component list here


file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/pol/*.hpp)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})


file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)


add_executable(pol ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(pol ${QT_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS pol RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

Now I'm trying to move to recent version of QT5, so I started like that:

cmake_minimum_required(VERSION 3.1.0)

project(pol)

add_compile_options(-std=c++17)

find_package(catkin REQUIRED COMPONENTS qt_build roscpp sensor_msgs cv_bridge image_transport)
find_package(OpenCV REQUIRED)
include_directories(${catkin_INCLUDE_DIRS})

catkin_package()
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Core Gui Widgets)

rosbuild_prepare_qt4(QtCore QtGui) # Add the appropriate components to the component list here

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/fmf_qt/*.hpp)

QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})

include_directories(
    ${Qt5Core_INCLUDE_DIRS}
    ${Qt5Gui_INCLUDE_DIRS}
    ${Qt5Widgets_INCLUDE_DIRS}
    )

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

add_executable(pol ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(pol Qt5::Widgets Qt5::Core ${QT_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS pol RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

Now I'm getting errors that I believe are due to my new CMakeLists such as

error: incomplete type ‘QImage’ used in nested name specifier
error: invalid use of incomplete type ‘class QImage’

The package is developed under ROS ubuntu 18.04 LTS and compiled with gcc 8.1 Do you know what's wrong with my new CMakeLists? The package was working with my old CMakeLists!

EDIT:

I run cmake correctly:

cmake ../src -DCMAKE_INSTALL_PREFIX=../install -DCATKIN_DEVEL_PREFIX=../devel

But I get the errors when I run make

5
  • Where do those errors come from -- when you run cmake or when you invoke make on the generated makefiles? Commented Jun 7, 2018 at 10:52
  • @G.M. when I run make I edited my post Commented Jun 7, 2018 at 10:57
  • On Stack Overflow we want code to be included into the question post itself, not linked. Please, fix that issue in your question. Commented Jun 7, 2018 at 12:20
  • @Tsyvarev I tried that but it was saying that there is too much code Commented Jun 7, 2018 at 12:21
  • 1
    Hm, strange. Both code snippets has less then 60 lines in total. But what is more vital, the error is in your .cpp code, not in the CMakeLists.txt. (That is, CMakeLists.txt could be bagged, but .cpp is bugged too). Commented Jun 7, 2018 at 12:24

2 Answers 2

3

This is how use Qt with cmake:

    cmake_minimum_required(VERSION 3.9)

    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)

    project(QCameraBug)

    # required packages
    find_package(Qt5 COMPONENTS Core Quick Multimedia REQUIRED)

    add_executable(${PROJECT_NAME} "main.cpp" "main.qrc")

    target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

    target_link_libraries(${PROJECT_NAME}
        Qt5::Core
        Qt5::Quick
        Qt5::Multimedia
    )

This works perfectly for me. Hope this is helpful

Sign up to request clarification or add additional context in comments.

Comments

1

You're getting these errors because the source file being compiled at the time is making use of QImage but the compiler can only see a forward declaration rather than the complete class definition.

For the source file(s) in question you need to add (assuming your include paths are correct)...

#include <QImage>

Previously, when using Qt4 the QImage header was probably being included transitively by one of the other Qt header files which is why there was no error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.