Load Custom Positioning Plugin for PositionSource
-
I am trying to use PositionSource in my Map project so that I can receive Latitude/Longitude data from another software in my network and update my map.
So I have done the following:
-
Created a custom Positioning plugin by implementing
QGeoPositionInfoSourceFactory
1.1) This Plugin implements a class that inheritsQGeoPositionInfoSourceand emitspositionUpdatedon my custom method that retrives data from the network. -
Added the plugin (dll) and a qmldir file to my QML project working directory
qmldir file:
module MyPosition plugin MyPositionPlugin- Tried inserting my plugin into PositionSource:
PositionSource { id: positionSrc updateInterval: 100 //ms name: "MyPositionPlugin" onPositionChanged: {...} }PROBLEM: onPositionChanged does not get called in
PositionSourceand when listingQGeoPositionInfoSource::availableSources()on my main, it does not list my plugin.P.S.: The plugin has the following MetaData in a json:
{ "Keys": ["SpectraPositionPlugin"], "Provider": "SpectraTecnologia", "Position": true, "Satellite": false, "Monitor": false, "Priority": 1000, "Testable": true }P.S.S: If I load the plugin using QPluginLoader on a regular Qt/C++ project, it works. The problem is with QML auto loader of plugins
-
-
Hi and welcome to devnet,
Silly question but did you install your plugin in the right folder of your Qt's installation ?
-
always do 'make install' for Qt plugins
-
Hi and welcome to devnet,
Silly question but did you install your plugin in the right folder of your Qt's installation ?
@SGaist
I was initially deploying my plugin in the Working Directory of my QML project. Now I have tried in thepositiondirectory inside Qt installation directory, but to no avail.In the project I am printing
QQmlApplicationEngine::pluginPathList()which returns:
(".")
And then I am checking the loaded plugins withQGeoPositionInfoSource::availableSources();I have also tried:
- Defining the environment variable QT_PLUGIN_PATH
- Created a
positiondirectory inside my working directory
@vladstelmahovsky
What do you mean bymake install?
After building my plugin project and generating a DLL, where should I do amake install? -
@SGaist
I was initially deploying my plugin in the Working Directory of my QML project. Now I have tried in thepositiondirectory inside Qt installation directory, but to no avail.In the project I am printing
QQmlApplicationEngine::pluginPathList()which returns:
(".")
And then I am checking the loaded plugins withQGeoPositionInfoSource::availableSources();I have also tried:
- Defining the environment variable QT_PLUGIN_PATH
- Created a
positiondirectory inside my working directory
@vladstelmahovsky
What do you mean bymake install?
After building my plugin project and generating a DLL, where should I do amake install?@guicc yes
-
The plugin should go in Qt's installation's location plugins folder.
-
@SGaist said:
The plugin should go in Qt's installation's location plugins folder.
I noticed a new clue to the problem. When activating the QT_DEBUG_PLUGINS environment variable, I had seen that my plugin is found:
Found metadata in lib C:/Qt/Qt5.6.0_x86/5.6/msvc2013/plugins/position/MyPlugin.dll, metadata= { "IID": "com.br.myplugin", "MetaData": { "Keys": [ "MyPlugin" ], "Monitor": false, "Position": true, "Priority": 1008, "Provider": "Me", "Satellite": false }, "className": "PluginFactory", "debug": false, "version": 329216 }But right after it prints the following:
Got keys from plugin meta data ()While that for other plugins I get:
Got keys from plugin meta data ("SerialPortNmea")I have already copied and written this plugin.json file 1000 times. Don't know what is wrong!
-
I managed to solve this problem by copying my code inside the Qt Source code. Since plugin
serialnmeaworks, I opened the project for this plugin at%QT_SRC%\qtlocation\src\plugins\positionand replaced the methods and classes with mine.At the end the code structure had one difference:
- My QGeoPositionInfoSource source declaration and definition is now placed together with the definition of my QGeoPositionInfoSourceFactory, inside a single .cpp file
The project .pro file also has a definition than it is not clearly specified in the Qt Documentation:
TARGET = MyPositionPlugin QT = core positioning network PLUGIN_TYPE = position PLUGIN_CLASS_NAME = PositionFactory load(qt_plugin) #this is the macro that modifies Makefile so that #it copies the final .dll to the Qt installation dir #in order for this to work, we also need a .qmake.conf file HEADERS += \ qgeopositioninfosourcefactory_serialnmea.h SOURCES += \ qgeopositioninfosourcefactory_serialnmea.cpp OTHER_FILES += \ plugin.jsonAnother important point that could be better explained in the Documentation: It is not the plugin key that should be inserted on
PositionSource, it is the provider!!This property holds the unique internal name for the plugin currently providing position information. .... If the specified positioning **provider** cannot be loaded the position source will become invalid. -
I managed to solve this problem by copying my code inside the Qt Source code. Since plugin
serialnmeaworks, I opened the project for this plugin at%QT_SRC%\qtlocation\src\plugins\positionand replaced the methods and classes with mine.At the end the code structure had one difference:
- My QGeoPositionInfoSource source declaration and definition is now placed together with the definition of my QGeoPositionInfoSourceFactory, inside a single .cpp file
The project .pro file also has a definition than it is not clearly specified in the Qt Documentation:
TARGET = MyPositionPlugin QT = core positioning network PLUGIN_TYPE = position PLUGIN_CLASS_NAME = PositionFactory load(qt_plugin) #this is the macro that modifies Makefile so that #it copies the final .dll to the Qt installation dir #in order for this to work, we also need a .qmake.conf file HEADERS += \ qgeopositioninfosourcefactory_serialnmea.h SOURCES += \ qgeopositioninfosourcefactory_serialnmea.cpp OTHER_FILES += \ plugin.jsonAnother important point that could be better explained in the Documentation: It is not the plugin key that should be inserted on
PositionSource, it is the provider!!This property holds the unique internal name for the plugin currently providing position information. .... If the specified positioning **provider** cannot be loaded the position source will become invalid. -
Hi and welcome to devnet,
What does your question have to do with this thread ?