Solved Bluetooth module not working with CMake
-
I have created two console projects with exactly same code which scans bluetooth devices and list them. Problem is if I use qmake (configuring using pro file) everything works seamlessly but if I run the project with built system CMake (cmakelist file) code runs but nothing happens. My environment is MacOs X 10 and QT 5.13.1
My cmakelist.txt file:
cmake_minimum_required(VERSION 3.5) set(CMAKE_PREFIX_PATH "/Users/gokcer/Qt/5.12.5/clang_64") project(hello 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(Qt5Core) find_package(Qt5Bluetooth) add_executable(hello main.cpp ServiceLocator.cpp ServiceLocator.h) target_link_libraries(hello Qt5::Core Qt5::Bluetooth)
My pro file:
QT -= gui QT += bluetooth CONFIG += c++11 console CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ ServiceLocator.cpp \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ ServiceLocator.h
Warnings I received when cmake version started:
objc[1032]: Class QMacAutoReleasePoolTracker is implemented in both /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore (0x109a23200) and /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore_debug (0x109290de8). One of the two will be used. Which one is undefined. objc[1032]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore (0x109a23278) and /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore_debug (0x109290e60). One of the two will be used. Which one is undefined. objc[1032]: Class KeyValueObserver is implemented in both /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore (0x109a232a0) and /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore_debug (0x109290e88). One of the two will be used. Which one is undefined. objc[1032]: Class RunLoopModeTracker is implemented in both /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore (0x109a232f0) and /Users/gokcer/Qt/5.12.5/clang_64/lib/QtCore.framework/Versions/5/QtCore_debug (0x109290ed8). One of the two will be used. Which one is undefined.
This is my first QT based project so maybe I am making some silly mistakes. Thank you for help.
-
When I compile project from command line everything worked. Probably problem was related with my IDE (CLion).