This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding pc-ble driver to Qt application

Hello,

I try to add the pc-ble driver from Nordic to my Qt application, but my application crashes all the time without a specific error. So I need some help with the implementation of the driver in my application (64 bit for windows).

Project file:

VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = 0

QT       += core gui serialport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11 file_copies

COPIES += packageSetup configSetup

# 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 \
           "VERSION_MAJOR=$$VERSION_MAJOR" \
           "VERSION_MINOR=$$VERSION_MINOR" \
           "VERSION_BUILD=$$VERSION_BUILD" \

# 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

RESOURCES += \
    Ressources.qrc

DEPENDPATH += \
    Nordic/nrf-ble-driver-4.1.4-win_x86_64/include/sd_api_v5 \

INCLUDEPATH += \
    Nordic/nrf-ble-driver-4.1.4-win_x86_64/include/sd_api_v5 \

SOURCES += \
    main.cpp \
    mainwindow.cpp \

HEADERS += \
    mainwindow.h \

FORMS += \
    mainwindow.ui \

TRANSLATIONS += \

LIBS += \
    -L$${PWD}/Nordic/nrf-ble-driver-4.1.4-win_x86_64/lib -lnrf-ble-driver-sd_api_v5-mt-4_1_4 \
    -L$${PWD}/Nordic/nrf-ble-driver-4.1.4-win_x86_64/lib -lnrf-ble-driver-sd_api_v5-mt-static-4_1_4 \

# Target version
VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_BUILD}

# Set the application icon
win32:RC_ICONS +=

# Set the build directories
CONFIG(debug, debug|release) {
    DESTDIR = debug
} else {
    DESTDIR = ../packages/com.daniel-kampert.DataDownloader/data
}

# Copy package and configuration files
CONFIG(debug, debug|release) {
    packageSetup.path = $$shell_quote($${OUT_PWD}/debug)
    configSetup.path = $$shell_quote($${OUT_PWD}/debug)
} else {
    packageSetup.path = $$shell_quote($${DESTDIR})
    configSetup.path = $$shell_quote(../config)
}

# Deployment rules
DEPLOY_COMMAND = $$(QTDIR)/bin/windeployqt
DEPLOY_OPTIONS = "--no-system-d3d-compiler --no-opengl --no-angle --no-opengl-sw"
DEPLOY_TARGET = $$shell_quote($$shell_path($${DESTDIR}/$${TARGET}.exe))
CONFIG(debug, debug|release) {
    DEPLOY_OPTIONS += "--debug"
} else {
    DEPLOY_OPTIONS += "--release"
}

QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_OPTIONS} $${DEPLOY_TARGET}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

void MainWindow::StatusHandler(adapter_t * Adapter, sd_rpc_app_status_t code, const char * message)
{
}

void MainWindow::ble_evt_dispatch(adapter_t * Adapter, ble_evt_t * p_ble_evt)
{
}

void MainWindow::log_handler(adapter_t* adapter, sd_rpc_log_severity_t severity, const char * message)
{
}

MainWindow::MainWindow(QWidget* parent) :   QMainWindow(parent),
                                            _mUi(new Ui::MainWindow)
{
    this->_mUi->setupUi(this);

    physical_layer_t * phy;

    phy = sd_rpc_physical_layer_create_uart("COM5", 1000000, SD_RPC_FLOW_CONTROL_NONE, SD_RPC_PARITY_NONE);
}

MainWindow::~MainWindow()
{
    delete this->_mUi;
}

Maybe someone can help me with the implementation Slight smile

Thank you

  • Hi,

    From the code that you pasted, it does not look like the application does much. There's several years since I last looked at Qt, but I assume that you are entering a main loop somewhere, so that it is not just the application exiting normally?

    What kind of crash is this, what return value do you get from the application, is it a segfault?

    Is there any logging from the application, so that you know how far it gets, and/or where it craches?

    How long does it take before it crashes, and does it always happen after the same amount of time?

    Regards,
    Terje

  • Hi ,

    sorry for the late response...

    The application shouldn't do much, because I want to identify the issue first (the application runs without any issues when I remove the SoftDevice code).

    The issue comes from the line

    phy = sd_rpc_physical_layer_create_uart("COM5", 1000000, SD_RPC_FLOW_CONTROL_NONE, SD_RPC_PARITY_NONE);

    and I don´t have any additional information about the reason for the crash, because Qt Designer only prints "The application has crashed" and the Debugger prints "The CDB process is closed" (CDB unexpected exit). And the amount of time is always the same.

  • Hi,

    No worries.

    I would check the way you do the hard coded serial port of "COM5". I am not sure what the compiler does with that string literal: If it stores it as a global constant, or if it goes out of scope. This might be a long-shot, but if it goes out of scope, that might be an issue. Can you try with a statically allocated string variable instead?

    Apart from that, figuring out how Qt Designer can give you any error return value, or any indication what went wrong (segfault, etc.), would be of great help. Or if you can run a debug session. Anything else would be unguided guesswork, really.

    Regards,
    Terje

  • Hi,

    I forgot to copy the DLL files. My application is working now.

Related