use the plugin and QT script at the same time
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?
:confused:
My plugin interface
Code:
class TaInterface
{
public:
virtual ~TaInterface() {}
public slots:
Load plugin and set to script engine
Code:
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);
}
}
}
DLL plugin
Code:
class AD
: public QObject,
public TaInterface
{
Q_OBJECT
Q_INTERFACES(TaInterface)
public:
~AD();
public slots:
};
Re: use the plugin and QT script at the same time
So what exactly doesn't work?
1 Attachment(s)
Re: use the plugin and QT script at the same time
The script file can't find the function which listed in the public slot in the interface.
I am new to the script. Can you please guide me what's wrong?
Code:
var functionName = AD.function();
print(functionName);
Re: use the plugin and QT script at the same time
does anybody have idea? I still can't figure out the way to use QT script to drive a plugin function.
Thanks for your attention!
Re: use the plugin and QT script at the same time
Does the AD object exist? Please provide a print of its properties (if you don't know how, search the web for printing properties of javascript objects).
2 Attachment(s)
Re: use the plugin and QT script at the same time
I think AD object is exist. After I load the AD plugin, I can use
Code:
QObject *plugin
= loader.
instance();
to get he QObject correctly. And I can use
Code:
Interface *ta = qobject_cast<Interface *>(plugin);
to set the QObject to correct class.
The ta->pluginName() is functional. However, when I assign this QObject to the script engine, the debugger can't recognize this object. I also do a comparison with QPushButton. If I sent the QPushButton to the script engine. The debugger shows every properties. Please find the detail pic in attached.
I don't know why the my plugin properties can't work well after I send the plugin object to script engine but the QPushButton works just fine?
Re: use the plugin and QT script at the same time
Quote:
Originally Posted by
SamT
I think AD object is exist.
I mean does it exist in the script context. Looks like it does (based on the pics you provide) and it seems a function() function is there, so everything should work. What's the problem then?
Re: use the plugin and QT script at the same time
Finally I got my script working.
I modify the implement of function()
Code:
void AD::function()
{
qDebug() << "This is a test";
}
and the script file
after runt the script, I could find my qDebug() window shows
The problem might go with the syntax error of my script file. Thanks for your help!