Results 1 to 8 of 8

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 06:49.

Similar Threads

  1. Replies: 5
    Last Post: 19th November 2010, 02:25
  2. Replies: 1
    Last Post: 8th October 2010, 11:38
  3. Replies: 6
    Last Post: 18th August 2010, 12:52
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03: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, 09: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.