Results 1 to 6 of 6

Thread: Qlibrary

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Qlibrary

    Ok, I have an interesting problem. Looking for as many ideas as possible here. I am building an application that uses plugins. The plugins add additional functionality to the main application without the application having any knowledge of its existance. The user can setup configuration files that specify what the app should do if a particular event or action is created (i.e. clicking a menu item, pressing a key combo). How would you guys allow the main application call a procedure inside the plugin with only a QObject pointer (given to you by the QPluginLoader) and a string consisting of the function to call.

    I have three different idea, and I am not sure if any will even work.

    Using QLibrary (this would be my last resort seeing as how these functions would have to be externed as "C" functions.

    Using QActions (not sure how I would do this, but I bet there is a way).

    Using Signals and Slots somehow (once again not sure).

    Currently, I am in the proof of concept phase of my project, and am looking for the cleanest ways to do this (that actually work). I might also be thinking about this in the wrong direction, so any suggestions are welcome.

    So to some things up here, how to you call a function from a library with nothing more than a QObject pointer, and a string?

    Thanks Everyone,
    Rian

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlibrary

    Well I think Qt has great plugin support. Take a look at this sample:
    Main App:
    http://doc.trolltech.com/4.1/tools-plugandpaint.html
    It's plugins:
    http://doc.trolltech.com/4.1/tools-p...asictools.html

    1) I would imagine that you would have to define interfaces that can be implemented by those plugins.
    2) The plugins should be placed in a known directory like done e.g. by Eclipse.
    3) Your app should offer a config dialog that would load all plugins and offer some details about each plugin to the user. (Like Name, What it does, ...)
    4) Let the user check the one's he would like to use with your app
    5) Save that configuration
    6) When your app starts, read the config and load the user selected plugins.

    Qt offers the QPluginLoader class for doing exactly that.

    If your interface defines methods, like getPluginName, getPluginDescription, getPluginCategory... then you would even be able to group those plugins in your app's config dialog. Or you group the plugins, based on the interface they implement from your app...

    there are lot's of possibilities ...

  3. #3
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlibrary

    This part I have working very nicely.The problem is. lets say a menu plugin has a function called test. How do you call test with nothing move than a string, "test" and a Object*

  4. #4
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlibrary

    How do you call test with nothing move than a string, "test" and a Object*
    If test() is a slot and the Object* is named foo:
    Qt Code:
    1. QMetaObject::invokeMethod( foo, "test" );
    To copy to clipboard, switch view to plain text mode 

    Hope this helps.

  5. #5
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlibrary

    That is a huge help. I had no idea that this even existed. Thanks, you probably saved the day!!!

  6. #6
    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: Qlibrary

    You can always have a method that returns a QAction * object (or better yet a list of QAction* objects). Your plugin doesn't have to return QObject * objects. You can create an "interface" containing custom methods too. Take a look at the docs about plugins in Qt4 for examples.

Similar Threads

  1. QLibrary resolve problem
    By Nippler in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 15:37
  2. Using Qlibrary on a function that uses arguments
    By schall_l in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2008, 21:58
  3. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 14:03
  4. Replies: 4
    Last Post: 7th March 2006, 08:52

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.