Can I use the plugin function and the QT script at the same program? That means to build a plugin DLL and load by plugin loader then I can use write a easy script to drive that plugin.
I try to implement this idea into my program. The plugin load successfully but I can't drive by the script. Does anybody uses this idea in your program? Any example for me to study?
My plugin interface
class TaInterface
{
public:
virtual ~TaInterface() {}
public slots:
class TaInterface
{
public:
virtual ~TaInterface() {}
virtual QString pluginName() = 0;
public slots:
virtual bool initialize(const QStringList &arguments, QString *errorString) = 0;
virtual QString function() = 0;
To copy to clipboard, switch view to plain text mode
Load plugin and set to script engine
void MainWindow::loadPlugins()
{
engine = new QScriptEngine(this);
pluginsDir
= QDir(qApp
->applicationDirPath
());
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
pluginsDir.cd("plugins");
foreach
(QString fileName, pluginsDir.
entryList(QDir::Files)) {
QObject *plugin
= loader.
instance();
if (plugin)
{
pluginFileNames += fileName;
Interface *ta = qobject_cast<Interface *>(plugin);
QScriptValue TaToScript = engine->newQObject(plugin);
engine->globalObject().setProperty(ta->pluginName(), TaToScript);
}
}
}
void MainWindow::loadPlugins()
{
engine = new QScriptEngine(this);
pluginsDir = QDir(qApp->applicationDirPath());
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
pluginsDir.cd("plugins");
foreach (QString fileName, pluginsDir.entryList(QDir::Files))
{
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin)
{
pluginFileNames += fileName;
Interface *ta = qobject_cast<Interface *>(plugin);
QScriptValue TaToScript = engine->newQObject(plugin);
engine->globalObject().setProperty(ta->pluginName(), TaToScript);
}
}
}
To copy to clipboard, switch view to plain text mode
DLL plugin
class AD
: public QObject,
public TaInterface
{
Q_OBJECT
Q_INTERFACES(TaInterface)
public:
~AD();
public slots:
};
class AD : public QObject, public TaInterface
{
Q_OBJECT
Q_INTERFACES(TaInterface)
public:
~AD();
bool initialize(const QStringList &arguments, QString *errorString);
QString pluginName();
public slots:
QString function();
};
To copy to clipboard, switch view to plain text mode
Bookmarks