Qt User Plugins & iOS
-
Hi All
I have developed Custom Qt Plugins(libDataStore.so) and used QPluginLoader to load the plugin in Android. It works fine..
How to use the same plugin in iOS ?. I know iOS talks about static plugin etc. When I build the same plugin using iOS kit, it build libDataStore.a. This is static lib.
How do i use this in iOS ? How to bundle this ? Does QPluginLoader works for this ? See the following sample code
QPluginLoader loader; loader.setFileName("libDataStore.a"); if(loader.load()){ qDebug() << Q_FUNC_INFO << " Plugin load successfull" << endl; QObject *obj = loader.instance(); if (obj==NULL){ qCritical() << "Plugin load failed. Please check "<<endl;return; } IDataStore *collector = qobject_cast<IDataStore*>(obj); connect(this,SIGNAL(storeDB()),obj,SLOT(start())); }else { qCritical() <<"Plugin load failed. Please check ="<< endl;return; }
Any inputs on this.
-
Hi,
It's explained here.
Just in case and IIRC, since Qt 5.9, you should also be able to build Qt dynamically on iOS but it's not yet currently fully automated for the bundling part so you might want to stay with the default current static build.
-
Thank @SGaist . Here is the complete info if somebody requires.
Plugin Side -
- First build your Qt plugin as static lib. For this place the following configuration in your plugin pro file.
CONFIG +=plugin static - My Plugin name is libDataStore.a & class name of the plugin is DataStore & Interface name is IDataStore
- Inside the constructor of DataStore, set the object name
e.g this.setObjectName("DataCollectorPlugin") - libDataStore.a is present in the directory called /Users/dheeru/Qt/bins
App Side -
- Place the configuration in application pro file like this
LIBS += -L/Users/dheeru/Qt/bins -lDataStore - Q_IMPORT_PLUGIN(DataStore) in main.cpp. Argument for the macro should match the classname
- Use QPluginLoader::staticInstances function. This will return the QObjects list. Since there may be many plugins, objectName is useful here.
- After this type cast the required object to Appropriate interface.
QObjectList objList = QPluginLoader::staticInstances(); foreach(QObject *obj1, objList){ qDebug() <<" IOS Load successful =" << obj1->objectName() << endl; IDataStore *collector = qobject_cast<IDataStore*>(obj1); if(collector!=NULL){ connect(this,SIGNAL(storeDB()),obj1,SLOT(start())); } }
Once you have object with you, rest of the process is same.
- First build your Qt plugin as static lib. For this place the following configuration in your plugin pro file.