How to use mavsdk shared library withint Qt 5 projects

I’m trying to write a simple Qt GCS application… I configured the project to use mavsdk shared library but when I try to compile my first project I got these errors:

It sounds like something related to C++ standard in use but I cannot find the way to specifiy language standard in Qt application project configuration.

Compiling mavsdk code outside Qt env works fine (i.e. using Eclipse CDT / g++).

What build system are you using? Qmake? Maybe something like this?

1 Like

yes it was… I needed to replace CONFIG entry c++11 with c++17.

May I ask the process you used to integrate MAVSDK with QGCS? I’m currently creating a custom version of QGCS, and I’m running into issues integrating the external MAVSDK library for use in it.

MAVSDK (at least the C++ part) is just a library. So you should be able to integrate it like any other library.

The files itself, so the headers and library files (e.g…so/.dylib/.dll) can either be installed system-wide, or relative in your directory. To generate the headers and library files you want to do an install into a local directory like.

If that’s still unclear I’d suggest to learn how libraries and dependencies work for C++ projects.

It really depends on what you are doing and what programming environment you’re going to use.
In Qt the only relevant change in default configuration was to add :
CONFIG += c++17
To application .pro file.
Programming a Linux console C++ application on Eclipse CDT you only need to correctly set include and libs folders in project settings and everything works.
I’m assuming you don’t need to make changes into MAVSDK … in such case you need to prep your programming env a little more.

Not really … mavsdk callbacks are not very useful inside Qt …

You could just call into Qt signal and slots from callback, right?

I don’t think it will work … in my experience overlapping with Qt event loop management will often result in failures. In my attempts I never succeeded in getting a mavsdk callback triggered within a Qt application but I did not do an extensive test at the moment.

Here’s a Qt sample code:

        missionServer = std::shared_ptr<mavsdk::MissionRawServer>(new MissionRawServer(gcs));

        missionServer->subscribe_incoming_mission(
            [&](mavsdk::MissionRawServer::Result result, mavsdk::MissionRawServer::MissionPlan plan){
                emit incomingMission(result, plan);
            }
        );

you can debug this and see that the callback is triggered as expected but the signal is not raised…

Interesting. Would you mind creating a minimal example for me to build and and reproduce?

@JulianOes
I finally managed to make it work. The problem was given by specific Qt requrements in signal/slot parameters type registration (to make it short I needed to use qRegisterMetaType, Q_DECLARE_METATYPE).
Anyway I wrote a short Qt widget app that try to mimic some feature of autopilot_server.cpp example provided within MAVSDK source (also because I’m unable to run autopilot_server since it always dumps cores).
If you wish to give it a look I can share it (here).

1 Like

Great, thanks for sharing!