labapart / gattlib

Library to access GATT information from BLE (Bluetooth Low Energy) devices
http://labapart.com/
436 stars 157 forks source link

Is it possible to use Gattlib with Qt? #183

Open jsochurek opened 3 years ago

jsochurek commented 3 years ago

I have a C++ command line app that works well using Gattlib to scan for Eddystone beacons and Eddystone-UID advertising data, connect to them, and write to them.

I tried to take the very same code and use it in a Qt program command line application, but any time I make an actual bluetooth call to scan for Eddystone beacons or connect to a beacon, it doesn't work. In the case of the scan, there is no output and the program hangs. When I try to directly connect to a beacon given that I know its address, it says the beacon "cannot be found".

I copied a basic Qt BLE scan program from the Qt docs, and confirmed I was able to scan for beacons that way using QtBluetooth. Both Gattlib and QtBluetooth use Bluez. This .pro file works for QtBluetooth but not Gattlib:

QT += bluetooth

CONFIG += c++11 console
CONFIG -= app_bundle

QT_FOR_CONFIG += bluetooth-private
QMAKE_USE += bluez
linux-*: {
    # bluetooth.h is not standards compliant
    CONFIG -= strict_c++
}

# 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 += \
        ble/Beacon.cpp \
        ble/BeaconScanner.cpp \
        ble/Eddystone.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 += \
    ble/Beacon.hpp \
    ble/BeaconActions.hpp \
    ble/BeaconScanner.hpp \
    ble/Eddystone.hpp \
    util/Scenario.hpp \
    util/json.hpp

QMAKE_CXXFLAGS += -std=c++0x -pthread
LIBS += -pthread
QMAKE_CFLAGS += -pthread

unix|win32: LIBS += -lgattlib

I'm just curious if anyone has managed to get Gattlib working from Qt.