Results 1 to 8 of 8

Thread: use the plugin and QT script at the same time

  1. #1
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?


    My plugin interface
    Qt Code:
    1. class TaInterface
    2. {
    3. public:
    4. virtual ~TaInterface() {}
    5. virtual QString pluginName() = 0;
    6.  
    7. public slots:
    8. virtual bool initialize(const QStringList &arguments, QString *errorString) = 0;
    9. virtual QString function() = 0;
    To copy to clipboard, switch view to plain text mode 

    Load plugin and set to script engine
    Qt Code:
    1. void MainWindow::loadPlugins()
    2. {
    3. engine = new QScriptEngine(this);
    4.  
    5. pluginsDir = QDir(qApp->applicationDirPath());
    6.  
    7. if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
    8. pluginsDir.cdUp();
    9.  
    10. pluginsDir.cd("plugins");
    11.  
    12. foreach (QString fileName, pluginsDir.entryList(QDir::Files))
    13. {
    14. QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
    15. QObject *plugin = loader.instance();
    16. if (plugin)
    17. {
    18. pluginFileNames += fileName;
    19. Interface *ta = qobject_cast<Interface *>(plugin);
    20.  
    21. QScriptValue TaToScript = engine->newQObject(plugin);
    22. engine->globalObject().setProperty(ta->pluginName(), TaToScript);
    23.  
    24. }
    25.  
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    DLL plugin
    Qt Code:
    1. class AD : public QObject, public TaInterface
    2. {
    3. Q_OBJECT
    4. Q_INTERFACES(TaInterface)
    5.  
    6. public:
    7. ~AD();
    8. bool initialize(const QStringList &arguments, QString *errorString);
    9. QString pluginName();
    10.  
    11. public slots:
    12. QString function();
    13.  
    14. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by SamT; 25th April 2011 at 07:49.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: use the plugin and QT script at the same time

    So what exactly doesn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

    Qt Code:
    1. var functionName = AD.function();
    2. print(functionName);
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. QObject *plugin = loader.instance();
    To copy to clipboard, switch view to plain text mode 
    to get he QObject correctly. And I can use
    Qt Code:
    1. Interface *ta = qobject_cast<Interface *>(plugin);
    To copy to clipboard, switch view to plain text mode 
    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?
    Attached Images Attached Images

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: use the plugin and QT script at the same time

    Quote Originally Posted by SamT View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use the plugin and QT script at the same time

    Finally I got my script working.

    I modify the implement of function()

    Qt Code:
    1. void AD::function()
    2. {
    3. qDebug() << "This is a test";
    4. }
    To copy to clipboard, switch view to plain text mode 

    and the script file
    Qt Code:
    1. AD.function();
    To copy to clipboard, switch view to plain text mode 

    after runt the script, I could find my qDebug() window shows
    Qt Code:
    1. This is a test
    2. nan
    To copy to clipboard, switch view to plain text mode 

    The problem might go with the syntax error of my script file. Thanks for your help!

Similar Threads

  1. Replies: 5
    Last Post: 19th November 2010, 03:25
  2. Replies: 1
    Last Post: 8th October 2010, 12:38
  3. Replies: 6
    Last Post: 18th August 2010, 13:52
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 04:01
  5. check the time of last time keyboard is pressed
    By Aki Tomar in forum General Programming
    Replies: 2
    Last Post: 5th February 2008, 10:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.