Results 1 to 3 of 3

Thread: plugin accessing data from qApp

  1. #1
    Join Date
    Jun 2013
    Location
    Germany
    Posts
    4
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default plugin accessing data from qApp

    Plugins are normally made for accessing plugin methods in the main program.

    Now I have an application, where the plugin needs to call a method from the main program.
    How is this done?
    I have a working solution using QMetaObject::invoke(),, but using this is rather complex.

    Is there an easier way to call an application method from within the plugin?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: plugin accessing data from qApp

    You can always specify a host API and give an object implementing that API to the plugin object.

    E.g.
    Qt Code:
    1. class HostApi
    2. {
    3. public:
    4. virtual void doSomething() = 0;
    5. };
    To copy to clipboard, switch view to plain text mode 
    The plugin API would then simply need something like
    Qt Code:
    1. class Plugin
    2. {
    3. public:
    4. virtual void setHost(HostApi *host) = 0;
    5. };
    To copy to clipboard, switch view to plain text mode 
    The host application can implement the API in any object it likes, it could even hand each plugin a different instance of the implementation or even different implementations.

    Cheers,
    _

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

    itpenguin (28th July 2016)

  4. #3
    Join Date
    Jun 2013
    Location
    Germany
    Posts
    4
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: plugin accessing data from qApp

    OK, my mistake was the declaration of doSomething(). It must be virtual, because the address of the method is allocated dynamically at run time.

Similar Threads

  1. Accessing data of .qml file
    By jeff28 in forum Newbie
    Replies: 1
    Last Post: 29th August 2012, 15:15
  2. QTableView : accessing the data
    By marvaneke in forum Newbie
    Replies: 10
    Last Post: 30th March 2012, 11:31
  3. Dynamic plugin: accessing parent's methods
    By codeslicer in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2011, 09:16
  4. Accessing data from a worker thread
    By steg90 in forum Qt Programming
    Replies: 20
    Last Post: 25th May 2007, 10:20
  5. accessing data in a QFile
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 16:25

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.