Unsolved QTplugin for beginner
-
@mrjj yes
-
Sorry. no idea. Google gives nothing.
Check against the sample.
Must be some difference since that works. -
@mrjj okay thanks
-
Might be silly question but I am stuck with it from very long at this point.
interface.h
#ifndef ECHOINTERFACE_H #define ECHOINTERFACE_H #include<QString> class EchoInterface { public: virtual ~EchoInterface() {} virtual QString echo(const QString &message) = 0; }; QT_BEGIN_NAMESPACE #define EchoInterface_iid "org.qt-project.Qt.Examples.EchoInterface" Q_DECLARE_INTERFACE(EchoInterface, EchoInterface_iid) QT_END_NAMESPACE #endif // ECHOINTERFACE_H
plugin_msg.h
#ifndef PLUGIN_MSG_H #define PLUGIN_MSG_H #include"echointerface.h" #include<QObject> class plugin_msg:public QObject,EchoInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.EchoInterface" ) Q_INTERFACES(EchoInterface) public: QString echo(const QString &message); plugin_msg(); }; #endif // PLUGIN_MSG_H
error:
error: C2259: 'EchoInterface': cannot instantiate abstract class due to following members: 'QString EchoInterface::echo(const QString &)': is abstract : see declaration of 'EchoInterface::echo' : C2059: syntax error:'string'//Q_DECLARE_INTERFACE(EchoInterface,EchoInterface_iid) : 'QObject' should be preceded by ';' // in qobjectdef_imp.h file
what is wrong?
-
Hi
EchoInterface::echo is pure virtual.
That is indicated with the =0 in end of line
virtual QString echo(const QString &message) = 0;That means your subclass MUSt implement it.
do you have
plugin_msg:: echo(const QString &message) {
...
}in the .cpp for plugin_msg?
-
@mrjj yes
-
Hi,
There's no sign of declaration nor implementation of the
echo
method in the code you posted from yourplugin_msg
class. -
@SGaist
plugin_msg.h#ifndef PLUGIN_MSG_H #define PLUGIN_MSG_H #include"echointerface.h" #include<QObject> class plugin_msg:public QObject,EchoInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.EchoInterface" ) Q_INTERFACES(EchoInterface) public: QString echo(const QString &message); plugin_msg(); }; #endif // PLUGIN_MSG_H
plugin_msg.cpp
#include "pluginmsg.h" #include "plugin_msg.h" plugin_msg::plugin_msg() { } QString plugin_msg::echo(const QString &message) { return message; }
-
@SGaist @mrjj hey thanks.my problem of interface is solved by just adding #include<QObject> before all the includes file in plugin_msg.h
now again I'm getting the same old problem of' Can not load plugins'.
"Failed to extract plugin meta data from 'C:/Users/Kits/Documents/build-plug_testit-Desktop_Qt_5_10_1_MSVC2017_64bit-Release/testitgui/Makefile'" "Failed to extract plugin meta data from 'C:/Users/Kits/Documents/build-plug_testit-Desktop_Qt_5_10_1_MSVC2017_64bit-Release/testitgui/Makefile.Debug'" "Failed to extract plugin meta data from 'C:/Users/Kits/Documents/build-plug_testit-Desktop_Qt_5_10_1_MSVC2017_64bit-Release/testitgui/Makefile.Release'" "Failed to extract plugin meta data from 'C:/Users/Kits/Documents/build-plug_testit-Desktop_Qt_5_10_1_MSVC2017_64bit-Release/testitgui/ui_mainwindow.h'"
-
-
@mrjj
mainwindow.cpp#include<QPluginLoader> bool MainWindow::loadplugin() { qDebug()<< qApp->applicationName(); pluginsDir = QDir(qApp->applicationDirPath()); qDebug()<<pluginsDir; #if defined(Q_OS_WIN) if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") pluginsDir.cdUp(); #elif defined(Q_OS_MAC) if (pluginsDir.dirName() == "MacOS") { pluginsDir.cdUp(); pluginsDir.cdUp(); pluginsDir.cdUp(); } #endif qDebug()<<"here.."<< pluginsDir.cd("plugins"); foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = pluginLoader.instance(); qDebug()<< pluginLoader.errorString(); if (plugin) { i = qobject_cast<interface *>(plugin); if (i) return true; } } return false; }
In analysis i found that
qDebug()<<"here.."<< pluginsDir.cd("plugins");
returns false.
but i don't know whether it creates "plugins" folder or it looks for the "plugins" folder already created or
Is it related to the DESTDIR in plugin.pro file.because in QT examples it automatically creates a folder named plugins in the build folder of the project, which isn't happening in my case.
plugin_msg.proTARGET =plugin_msg TEMPLATE = lib CONFIG += plugin QT += widgets INCLUDEPATH +="C:\Users\Kits\Documents\plugin_task\GUI_msg" HEADERS += \ plugin.h SOURCES += \ plugin.cpp TARGET = $$qtLibraryTarget(pnp_plugin) DESTDIR = "C:\Users\Kits\Documents\plugin_task\plugins" DISTFILES += \ Echoplugin.json
-
The loader you use , looks for the plugins in a folder next to .exe
and tried to go up and down depending on release and build.
and then tries to enter plugins.So check you do in fact have that folder in that location and it has the DLL file.
Alternatively, just load it directly with absolute path for test.
-
@mrjj thanks a lot for your answer and for the link https://suppsforlife.to/category/pct/
also wanted to say thanks to everyone for all your answers as they were super helpful for me, as a beginner. was wondering if i may talk with your privately guys? or I should start a thread? -
@Offied
Hi ( JadeN001 in office ?)
Please make posts versus asking chat.
Chat is bad for viewing code and nobody else can
see the questions / answers or help with info so
forum posts are always the best and help all the most.
I assume by privately you mean in chat and not something else:) -
By the way, did you try adding the .json file with the plugin metadata to your project ?
-
@SGaist sorry for late reply..
YEAH, I added .jason file with ["keys" : pluginname] but it does not make any changes. -
@SGaist @mrjj thank you very much..
my problem is solved. I think there is problem on path that i have mentioned in pro files.I am not clear exactly which part of pro file solved my problem.but i am sure that you have to set path for the plugins folder properly.
another thing that i have changed is DESTDIR.previously it was :
DESTDIR = "C:\Users\Kits\Documents\plugin_task\plugins"
now,
DESTDIR =...\plugins.
i don't know the reason how it made effect.but some changes solved my problem.
updated pro files :plugin_msg.pro TEMPLATE = lib CONFIG += plugin QT += widgets INCLUDEPATH +="C:\Users\Kits\Documents\plugin_GUI\GUI_msg" HEADERS += \ echoplugin.h SOURCES += \ echoplugin.cpp TARGET = $$qtLibraryTarget(echoplugin) DESTDIR = ..\plugins EXAMPLE_FILES = echoplugin.json # install target.path = $$[QT_INSTALL_EXAMPLES]C:\Users\Kits\Documents\plugin_GUI\plugins INSTALLS += target CONFIG += install_ok # Do not cargo-cult this DISTFILES += \ Echoplugin.json
GUI_msg.pro
#------------------------------------------------- # # Project created by QtCreator 2018-06-02T15:11:41 # #------------------------------------------------- QT += core gui QT += network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = GUI_msg TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ mainwindow.cpp \ server_task.cpp \ dialog_broadcast.cpp \ dialog_sendtoparticularclient.cpp HEADERS += \ mainwindow.h \ echointerface.h \ server_task.h \ dialog_broadcast.h \ dialog_sendtoparticularclient.h FORMS += \ mainwindow.ui \ dialog_broadcast.ui \ dialog_sendtoparticularclient.ui QMAKE_PROJECT_NAME = mainwindow win32 { CONFIG(debug, release|debug):DESTDIR = ../debug/ CONFIG(release, release|debug):DESTDIR = ../release/ } else { DESTDIR = ../ } # install target.path = $$[QT_INSTALL_EXAMPLES]C:\Users\Kits\Documents\plugin_GUI INSTALLS += target CONFIG += install_ok # Do not cargo-cult this!
if anyone know what makes pluginsDir.cd("plugins"); to true,i will bit more clear.
-
Congrats. your first plugin :)
-
@mrjj thanks :)