Results 1 to 6 of 6

Thread: Dynamically loading libraries

  1. #1
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Dynamically loading libraries

    Hi.
    Is there way in QT5 to load libraries dynamically by other library?
    I want to do something like that:
    My program is loading main library and that library have access to other libraries. I don't want to link them all in my program, because when I want to add some others libs, then I have to release new version of my program. I want to release just new version of main library.
    Is it possible to do so?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Dynamically loading libraries

    Is there way in QT5 to load libraries dynamically by other library?
    Yes you can use QLibrary to load shared libraries at runtime. And it is assumed that you main library is build on Qt.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Dynamically loading libraries

    I read about libraries and plugins, and I see that if I want to import whole class, I need to declare my library as plugin. So i did something like this:
    my lib:
    Qt Code:
    1. class MAILSYSTEMSHARED_EXPORT MainlLib : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDummyPlugin")
    5. public:
    6. MainLib(QString variable);
    7. }
    To copy to clipboard, switch view to plain text mode 
    loading in main.cpp:
    Qt Code:
    1. QPluginLoader *loader = new QPluginLoader("Mailboxes/lib/libMainLib.so");
    2. QObject *object = loader->instance();
    3. MainLib *lib = qobject_cast<MainLib *>(object);
    To copy to clipboard, switch view to plain text mode 

    Now if I have parameters in MainLib, I get no matching function for call to MainLib::MainLib(), candidate is MainLib::MainLib(QString, QString, QString), in file moc_MainLib.cpp
    When I remove parameters, in main program I get: undefined reference to `MainLib::staticMetaObject'
    What should I do?
    Thanks

  4. #4
    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: Dynamically loading libraries

    Plugin classes require a default constructor.
    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.


  5. #5
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Dynamically loading libraries

    Could you tell me, how can I resolve symbol for class? what symbol should I use?

    Edit: ok, I found solution, thanks
    Last edited by januszmk; 4th February 2013 at 15:28.

  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: Dynamically loading libraries

    Basically your problem is that you are trying to put class A into a plugin but still make it known to the main program. This is not going to work if the class has the Q_OBJECT macro set. You need a common interface for all your classes that you want to load dynamically into the main application.
    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.


Similar Threads

  1. Delay-loading libraries... And MinGW.
    By hickscorp in forum Newbie
    Replies: 0
    Last Post: 13th April 2012, 00:23
  2. Replies: 4
    Last Post: 5th November 2011, 01:38
  3. Dynamically Loading UI With Unspecified Slots
    By spraff in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2010, 10:46
  4. Replies: 2
    Last Post: 3rd December 2009, 06:04
  5. Dynamically Loading a QMainWindow?
    By natron in forum Newbie
    Replies: 10
    Last Post: 21st July 2006, 01:15

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.