Results 1 to 7 of 7

Thread: Loading/Initializing classes

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Loading/Initializing classes

    I'm trying to port a project of mine from python to c++. In my python project I had a few classes that were kind of plugins. They all were in a folder called "plugins", and each plugin had it's folder and a main.py file.

    I took the idea from here. http://www.evanfosmark.com/2009/07/s...tem-in-python/
    So, as you can see, each main file (aka each main file of each plugin) was "imported" (aka loaded/initialized).
    Is there something similar in C++? How can I load all classes at once?

    Thanks

    PS: Yes, I already saw the PLUGIN_EXPORT2 & _LOAD, but I'm not really sure to want that exactly.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading/Initializing classes

    C++ does support dynamic loading of libraries. The Qt plug-in system is the easiest solution to what you want since it already implemented the necessary functionality. Else you will have to write library loading, function resolving and other tedious platform specific stuff yourself (which is obviously possible and a good way to learn the specifics).
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading/Initializing classes

    So, after reading a lot I got to the conclusion that this is not possible as C++ doesn't have reflections like C# or Java.
    I saw the factory pattern, but this is just a big if-else, and that's just ugly.

    Thanks anyway!

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading/Initializing classes

    Well C++ is still a low-level language... You have to program the reflection into it
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  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: Loading/Initializing classes

    Quote Originally Posted by alexandernst View Post
    I saw the factory pattern, but this is just a big if-else, and that's just ugly.
    You don't need any big if-elses, it's just a matter of how you design your plugin system. The only "if" you need is the one to check if the plugin was loaded and initialized successfully.
    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
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading/Initializing classes

    So, do you have any links where I could get some examples?

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Loading/Initializing classes


Similar Threads

  1. QT WMI Classes
    By justatiq in forum Qt Programming
    Replies: 31
    Last Post: 10th April 2011, 15:44
  2. Replies: 1
    Last Post: 23rd September 2010, 17:12
  3. Delay initializing?
    By MorrisLiang in forum Newbie
    Replies: 4
    Last Post: 23rd August 2010, 15:37
  4. Initializing a QList of QHashes
    By Cruz in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2009, 16:24

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.