Results 1 to 2 of 2

Thread: Plugin interface to allow plugin to call a member function of the application

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Plugin interface to allow plugin to call a member function of the application

    Hello,

    while it is quite clear how to write an interface so that the application can interact with the plugin by calling some of it member functions, I would like to now how I can have the plugin interacting with the application by letting him call some member functions declared in the application.

    The following code shows how the application could display some message in the plugin by having the application calling a member function of the plugin.

    Qt Code:
    1. class MyInterface
    2. {
    3. public:
    4. virtual ~MyInterface() {}
    5. virtual QString displayInPlugin(const QString &message) = 0;
    6. };
    7.  
    8. Q_DECLARE_INTERFACE(MyInterface, "myApplication/1.0");
    To copy to clipboard, switch view to plain text mode 

    Now I am looking for the other way around, give the plugin the possibility to call a member function of the application.

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Plugin interface to allow plugin to call a member function of the application

    You can do it in two ways ( at least ).
    1. Declare a signal in a plugin, connect application's slot to it, and emit this signal
    2. You can derive your application from another interface ( say: IMainProgram ), and give the pointer to this interface to your plugin
    Qt Code:
    1. class IMainProgram {
    2. public:
    3. virtual void doSmth() = 0;
    4. };
    5. class Plugin
    6. {
    7. public:
    8. Plugin( IMainProgram * mainProgram )
    9. : m_mainProgram( mainProgram )
    10. {}
    11. void foo() {
    12. m_mainProgram->doSmth();
    13. }
    14. protected:
    15. IMainProgram * m_mainProgram;
    16. };
    17. class MainWindow : public QMainWindow, public IMainProgram {
    18. ...
    19. virtual void doSmth() {}
    20. ...
    21. void createPlugin() {
    22. plugin = new Plugin( this );
    23. }
    24. };
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to borisbn for this useful post:

    schall_l (10th October 2010)

Similar Threads

  1. Replies: 7
    Last Post: 11th April 2013, 11:55
  2. Plugin and shared class between plugin and application
    By wishper in forum Qt Programming
    Replies: 7
    Last Post: 23rd August 2010, 18:00
  3. Replies: 2
    Last Post: 7th July 2009, 18:44
  4. How to call the C++ member function from the JScript
    By parusri in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2008, 11:13
  5. interface on plugin
    By tranfuga25s in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2008, 21:56

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.