2
votes

I have a QML plugin compiled (to a .so) by another project. I want to re-use this in my own QML application without re-building it each time. I want to copy the .so over and, with minimal additional code, be able to write:

import QQuickMapboxGL 1.0

at the top of my QML files and have it work.

Where do I need to copy the .so in my QML project, and how do I need to add it to the project so that the QML runtime can find it?


What I've tried:

  1. Create a QQuickMapboxGL directory with libqmapboxgl.so in it.
  2. Create a qmldir file in that directory with the contents:

    plugin qmapboxgl
    
  3. Add the following to my .pro file:

    INSTALL_DIR = $$PWD/../install
    target.path = $$INSTALL_DIR
    
    # Copy the QQuickMapboxGL folder to the install directory
    plugin.files = QQuickMapboxGL/*
    plugin.path  = $$INSTALL_DIR/QQuickMapboxGL
    
    INSTALLS += target plugin
    
  4. Add a make install build step.

The result of this mad hackery was:

plugin cannot be loaded for module "QQuickMapboxGL": Plugin verification data mismatch in '/my/build/QQuickMapboxGL/libqmapboxgl.so'

I have verified that the plugin and my application are both being compiled with the same version of g++ (g++-5 (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904) and the same Qt download (5.7.0).

1
What this library is? A QML plugin? - folibis
@folibis Yes. It is QQuickMapboxGL from here. - Phrogz
I guess the path should be 'appPath/imports/pluginName/plugin.dll' - folibis
@Redanium Did you forget to add your comment after providing those links? Was there a particular piece of information you were suggesting, beyond "RTFM"? The plugin has already been created. I'm asking about a specific error when attempting to include it in my project. Is there something relevant in either of those links that I'm missing? - Phrogz

1 Answers

0
votes

The main problem is that the .so is not a QML Plugin; no class inherits from QQmlExtensionPlugin or related. It is just a shared library of code.

Was able to workaround this by:

  • Adding the header files for MapboxGL to my project
  • In my main.cpp:
    • #include "3rdparty/mapbox-gl-native/platform/qt/include/qmapbox.hpp"
    • Calling QMapbox::registerTypes(); (inside main)
  • Copying libmapboxgl.so (built via Mapbox's make/cmake) inside a libs directory.
  • In myproject.pro adding: LIBS += -L./libs -lqmapboxgl
  • In my QML code import QQuickMapboxGL 1.0 and then using MapboxMap
  • Copying libmapboxgl.so to somewhere that is referenced by LD_LIBRARY_PATH