QT6 Insists on using cdb instead of gdb - c++

I am using Qt 6.0.4 in Win10, the 'Help/About' says QtCreator version is 4.15.0. I have a very simple desktop application, built using CMake, and using QCustomPlot that crashes. I am using the Kit Qt 6.0.4 mingw81_64. When I look into the settings under manage kits, I see the debugger is supposedly set to 'GNU gdb 8.1 for MinGW 8.1.0 64Bit'. But when I start debugging, I get a message box that seems to indicate it is using cdb, not gdb. In the Debuggers tab for the kit, it shows all the GNU gdb debuggers, but also to CDB, all auto-detected. I can not remove the cdb entries, at least not that I can figure out. How do I turn off cdb so it only uses the gdb that seems to be called for in the kit settings??
My CMakeLists.txt file is:
project(QT60DataAcq VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package( ...) calls below.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(QT NAMES Qt6 COMPONENTS Widgets PrintSupport REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets PrintSupport REQUIRED)
include_directories(C:/Pgms/Qt/QCUSTOMPLOT2X)
set(PROJECT_SOURCES
main.cpp
dacqmain.cpp
dacqmain.h
dacqmain.ui
C:/Pgms/Qt/QCUSTOMPLOT2X/qcustomplot.cpp
)
set(CMAKE_BUILD_TYPE Debug)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(QT60DataAcq
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
if(ANDROID)
add_library(QT60DataAcq SHARED
${PROJECT_SOURCES}
)
else()
add_executable(QT60DataAcq
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(QT60DataAcq PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::PrintSupport)
set_target_properties(QT60DataAcq
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(QT60DataAcq)
endif()

Related

How can I add QtCharts library to my project?

I was trying to add QtCharts library to my project but an error occurred:
Target "PTP3" links to target "Qt6::Charts" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
I installed Qt5::Charts and Qt6::Charts via Qt MaintenanceTool but the issue remained. Anyone knows how to fix it?
I'm using Qt Creator 7.0.2. Here is my Cmake file. I followed the instructions from https://doc.qt.io/qt-6/qtcharts-index.html but it didn't help.:
cmake_minimum_required(VERSION 3.5)
project(PTP3 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Charts REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
set(PROJECT_SOURCES
main.cpp
footballmatches.cpp
footballmatches.h
footballmatches.ui
pivottable.h
pivottable.cpp
pivottable.ui
stadiumschart.h
stadiumschart.cpp
stadiumschart.ui
some_qml.qml
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(PTP3
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET PTP3 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(PTP3 SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(PTP3
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(PTP3 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(PTP3 PRIVATE Qt${QT_VERSION_MAJOR}::Charts)
set_target_properties(PTP3 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(PTP3)
endif()
you should have both these lines in your Cmake File for adding one of the qt libs to your project for example for qt charts you need these:
find_package(Qt5Charts REQUIRED)
target_link_libraries(${PROJECT_NAME}
Qt5::Charts
)
Be sure to add target_link_libraries at the end of your CMakeLists.txt file.

Cannot use Qt Charts - QT6 | Cmake

I am using Qt 6.2.1 with cmake and I can't find a way to use Qt Charts.
The Qt Charts is installed under "C:\Qt\6.2.1\Src\qtcharts"
In my cmakelists.txt I've included the Qt Charts in find_package and target_link_libraries. That seemed to work on qt5 (found on other answers in StackOverflow) but don't work on qt6. (I've hidden the project sources files)
cmake_minimum_required(VERSION 3.5)
project(projectname VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG "/MDd")
find_package(QT NAMES Qt6 COMPONENTS Widgets Charts REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Xml Widgets REQUIRED)
set(PROJECT_SOURCES
...
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(projectname
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
add_executable(projectname
${PROJECT_SOURCES}
)
endif()
target_link_libraries(projectname PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Xml Qt6::Charts)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(projectname)
endif()
I get this error:
C:\Qt\6.2.1\msvc2019_64\lib\cmake\Qt6Core\Qt6CoreMacros.cmake:559: error: Target "projectname" links to target "Qt6::Charts" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? C:/Qt/6.2.1/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:523 (_qt_internal_create_executable) C:/Qt/6.2.1/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:847 (qt6_add_executable) CMakeLists.txt:78 (qt_add_executable)
SOLUTION (Thanks to #vre):
I had to select the Qt Charts under 6.2.1 and not under Qt in the online installer
Qt Online Installer

Qt6 desktop app and shared library with cmake

I am trying to make a project with subdirectories using cmake.
When using qmake this mechanism was built in Qt creator.
The project contains a shared library and a desktop app.
Below is the structure of the project and cmake I have:
Main cmake:
cmake_minimum_required (VERSION 3.5)
project(contractapp)
add_subdirectory(contract-core)
add_subdirectory(contract-desktop)
Desktop app cmake:
project(contract-desktop LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package( ...) calls below.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(contract-core REQUIRED)
set(PROJECT_SOURCES
main.cpp
MainWindow.cpp
MainWindow.h
MainWindow.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(contract-desktop
${PROJECT_SOURCES}
)
else()
if(ANDROID)
add_library(contract-desktop SHARED
${PROJECT_SOURCES}
)
else()
add_executable(contract-desktop
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(contract-desktop PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
Shared library cmake:
cmake_minimum_required(VERSION 3.14)
project(contract-core LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
add_library(contract-core SHARED
contract-core_global.h
Person.cpp
Person.h
)
target_link_libraries(contract-core PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(contract-core PRIVATE CONTRACTCORE_LIBRARY)
My problem is that the desktop application does not see the library that I am making.
That library has to be copied to the same folder the application is in. Otherwise, each is in its own folder, and the application won't see it. Most likely you'd want to set the target folder for both binaries (the application and the library) to be some common build subfolder of both.

QColorSpace: No such file or directory

I'm trying to run the imageviewer example from this website https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html.
However, for some reason I don't seem to have QColorSpace.
I tried to include all of the possible libraries I thinnk I would need but still have no luck.
Is it my CMake file or do I need to somehow install QColorSpace?
cmake_minimum_required(VERSION 3.5)
project(SAT_Solver LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets PrintSupport OpenGL Core Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets PrintSupport OpenGL Core Gui REQUIRED)
if(ANDROID)
add_library(SAT_Solver SHARED
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
ScribbleArea.cpp
ScribbleArea.h
)
else()
add_executable(SAT_Solver
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
ScribbleArea.cpp
ScribbleArea.h
imageviewer.h
imageviewer.cpp
)
endif()
#qt5_add_resources(RC_SRC "resources/qml.qrc")
#qt5_add_resources(RC_SRC "/home/nalfredo/School/AutoSoftware/Project/QT/SAT_Solver/Resources.qrc")
target_link_libraries(SAT_Solver PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::PrintSupport
${QT_QTSVG_LIBRARY} Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Core Qt5::Gui)

LINK : fatal error LNK1181: cannot open input file '\machine:x64.obj'

I am porting a C++ project I have been working on for 2 years, to Windows, and I am facing this link issue, that I haven't seen on any google-referenced posts... :/
It is a CMake-generated project, and I get these CMake entries set by default to "\machine:x64"
CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS
I tried removing the flag, which has no effect on any of the 3 last entries, but CMAKE_EXE_LINKER_FLAGS without this value gives me about 85 unresolved externals spread in my libraries.
ALL my projects / project dependencies are compiled with MSVC2015 in x64.
Linking fails both in debug & release mode (not that it matters..)
I should also probably mention that I have 6 projects in this solution, 4 libraries, 2 executables. 4 of these projects are compiling fine (1 executable & 4 libs), only the 2 last ones are failing (with the same link error for both).
The only difference in terms of dependencies are a dependency to the Point Cloud Library (pcl), and to Qt5 (Core GUI, XML, and OpenGL)
Did anyone already encountered this specific linker error?
Hope you can help =)
EDIT: Here are the 2 main CMakelists files (the one at the root of the project and the one that compiles both failing projects). I removed everything that didn't seem pertinent for this issue.
Root CMakeLists.txt:
project(SofaOR)
cmake_minimum_required(VERSION 2.4)
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR})
#Reading local file for the non automatically detected dependencies
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies.cmake")
message("Adding custom file")
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies.cmake)
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
set(SOFA_ALL_LIBS SofaHelper SofaDefaultType)
set(SOFA_INCLUDE_DIRS ${SOFA_DIR}/include)
set(SOFA_LIBRARY_DIRS ${SOFA_DIR}/lib)
add_subdirectory(${CMAKE_SOURCE_DIR}/processOR)
the CMakelists included by the last add_subdirectory:
project(processOR)
cmake_minimum_required(VERSION 3.0.2)
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(PROCESSOR_EXEC_NAME processOR)
set(PROCESSOR_LIB_NAME processOR_lib)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(OpenCV COMPONENTS core imgproc xfeatures2d calib3d REQUIRED )
find_package(Qt5 COMPONENTS Core Gui Xml OpenGL REQUIRED )
find_package(PCL COMPONENTS common io kdtree REQUIRED )
find_package(Boost COMPONENTS program_options chrono thread REQUIRED)
find_package(OpenIGTLink REQUIRED )
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(PROCESSOR_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/src/ PARENT_SCOPE)
set(PROCESSOR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/)
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${COMMON_INCLUDE_DIRS})
include_directories(${OpenIGTLink_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${QGLVIEWER_DIR})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${SOFA_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
link_directories(${COMMON_LIBRARY_DIRS})
link_directories(${OpenIGTLink_LIBRARY_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})
link_directories(${QGLVIEWER_DIR})
link_directories(${SOFA_LIBRARY_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${PROCESSOR_SRC})
set(PROCESSOR_ALL_LIBS
${PCL_LIBRARIES}
${COMMON_LIBRARIES}
OpenIGTLink
${OpenCV_LIBS}
QGLViewer
${Boost_LIBRARIES}
${SOFA_ALL_LIBS}
)
set (HEADER_FILES
${PROCESSOR_SRC}/util/Calibration.h
${PROCESSOR_SRC}/fetchers/VideoFetcher.h
[…]
${PROCESSOR_SRC}/filters/PointCloudTriangulator.h
${PROCESSOR_SRC}/filters/PointCloudSmootherMLS.h
${PROCESSOR_SRC}/filters/PointCloudSegmenter.h
${PROCESSOR_SRC}/filters/PointCloudDownSampler.h
)
set (SOURCE_FILES
${PROCESSOR_SRC}/Registrator.cpp
${PROCESSOR_SRC}/tinyxml2.cpp
[…]
${PROCESSOR_SRC}/filters/PointCloudSegmenter.cpp
${PROCESSOR_SRC}/filters/PointCloudDownSampler.cpp
)
# Library
add_library(${PROCESSOR_LIB_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROCESSOR_LIB_NAME} ${PROCESSOR_ALL_LIBS} ${CMAKE_EXE_LINKER_FLAGS} ${ADDITIONAL_LIBRARIES})
QT5_USE_MODULES(${PROCESSOR_LIB_NAME} Widgets Gui OpenGL Xml)
set(PROCESSOR_LIB ${PROCESSOR_LIB_NAME} PARENT_SCOPE)
# Main executable
set (SOURCE_FILES
${PROCESSOR_SRC}/mainRegistration.cpp
)
add_executable(${PROCESSOR_EXEC_NAME} ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROCESSOR_EXEC_NAME} ${PROCESSOR_LIB} ${Boost_LIBRARIES} ${PROCESSOR_LIB_NAME} ${CMAKE_EXE_LINKER_FLAGS})
QT5_USE_MODULES(${PROCESSOR_EXEC_NAME} Widgets Gui OpenGL Xml)
set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)