Results 1 to 8 of 8

Thread: A whole Qt program as dynamic link lib?

  1. #1
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default A whole Qt program as dynamic link lib?

    Hi, before I try it myself I'd like to ask if someone has tried this: Is it possible to have a whole Qt program with event loop and all made into a normal non-Qt dynamic lib? I would want to load it into a non-Qt program and control it via a custom interface, e.g. calling a 'start' function should bring up the gui as if it was started from a normal main function.

    I don't see a reason why this would not work, but perhaps someone has first hand experiences?

    Don't ask me why I need this. Customer wishes.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A whole Qt program as dynamic link lib?

    It is possible, but makes no sense.
    You will have to link Qt statically against your lib, which will make it quite large.
    It has other disadvantages too.

    Ask your client why he wants this, if he is paying you to code, this means he doesn't know much about coding him self, so he should tell you what is the result he want, not how you should you implement it on a technical level.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: A whole Qt program as dynamic link lib?

    Quote Originally Posted by high_flyer View Post
    It is possible, but makes no sense.
    You will have to link Qt statically against your lib, which will make it quite large.
    It has other disadvantages too.
    So it is not possible to have a Qt program as dynlib, which itself loads the qt libs dynamically?

    Quote Originally Posted by high_flyer View Post
    Ask your client why he wants this, if he is paying you to code, this means he doesn't know much about coding him self, so he should tell you what is the result he want, not how you should you implement it on a technical level.
    Easy. He wants to add 'programs' to a main program like a dockwidget. But since he does not trust Qt it must not be via a Qt interface. A qt main program and adding functionality as Qt-plugins would be trivial. Unfortunately I have to 'wrap' a Qt program into a non-Qt library.

  4. #4
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A whole Qt program as dynamic link lib?

    You can just link dynamically and preload Qt library to speed the process or if Qt libraries resides in some uncommon places where OS cannot find it. This is simple dlload system call. See your OS manual for details.

  5. #5
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: A whole Qt program as dynamic link lib?

    Quote Originally Posted by Tanuki-no Torigava View Post
    You can just link dynamically and preload Qt library to speed the process or if Qt libraries resides in some uncommon places where OS cannot find it. This is simple dlload system call. See your OS manual for details.
    I wish it was so easy. Something I must be doing wrong. I chose in .pro 'lib' as template. Result is, I get a nice .so file. ldd shows all dependencies are fine. But as soon as the link loader tries to load this lib I get a segfault. Even if the lib is totally empty. As long as I have a CONFIG+= qt in my .pro I get a segfault.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A whole Qt program as dynamic link lib?

    Easy. He wants to add 'programs' to a main program like a dockwidget. But since he does not trust Qt it must not be via a Qt interface. A qt main program and adding functionality as Qt-plugins would be trivial. Unfortunately I have to 'wrap' a Qt program into a non-Qt library.
    It sounds to me you are confusing things, or/and don't understand some other things.
    To make sure we all speak the same language lets agree on some definitions:
    "Qt vs 'Non Qt" - I am not sure what it is you mean by either.
    A Qt application is an application which links against a Qt lib, at the very minimum.
    So if you link against Qt, be it dynamically or statically, you have a Qt application.
    The question is, if you are using Qt, what sense does it make to wrap it in API that will "shield" you from the Qt API?

    The explanation you gave as :
    Easy. He wants to add 'programs' to a main program like a dockwidget. But since he does not trust Qt it must not be via a Qt interface.
    Doesn't really answer anything.

    If he doesn't "trust" Qt (what ever that means), then just don't work with Qt, and that is the end of it.

    Again, you can have a Qt lib, and expose from that lib just normal C/C++ API which does not use signals/slots etc.
    But the lib it self will be Qt code, so I its just makes no sense.

    I suggest you:
    1. Get a clear description of what the application should do.
    2. Choose the best framework for that task.
    3. Tell you customer to worry about what he wants, and let you worry about how to implement it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: A whole Qt program as dynamic link lib?

    Quote Originally Posted by high_flyer View Post
    The question is, if you are using Qt, what sense does it make to wrap it in API that will "shield" you from the Qt API?
    Do not ask me, ask my customer. It's a requirement I have and the customer is king.

    Quote Originally Posted by high_flyer View Post
    The explanation you gave as :

    Doesn't really answer anything.

    If he doesn't "trust" Qt (what ever that means), then just don't work with Qt, and that is the end of it.
    I have to use Qt, this is also a requirement.
    The customer just wants to link several programs into some sort of main program. Therefore I am required to write the programs as dynlibs. But he wants the interface totally Qt free, so he can replace my programs at any times with identical programs, which are not Qt based.

    Stupid? Maybe, maybe not. It is as it is and I am doing what I am paid for.

    Quote Originally Posted by high_flyer View Post
    Again, you can have a Qt lib, and expose from that lib just normal C/C++ API which does not use signals/slots etc. But the lib it self will be Qt code, so I its just makes no sense.
    Wrong, I can have a Qt lib, which exposes just normal C/C++ API, but still uses
    signal/slots internally. Problem was that I did it wrong. That's why I asked here if it is possible at all and how to do it. Not to question the whole architecture, which is not mine and not mine to decide.

    Quote Originally Posted by high_flyer View Post
    I suggest you:
    1. Get a clear description of what the application should do.
    I did.

    Quote Originally Posted by high_flyer View Post
    2. Choose the best framework for that task.
    Can't. I am just a lowly code monkey here.

    Quote Originally Posted by high_flyer View Post
    3. Tell you customer to worry about what he wants, and let you worry about how to implement it.
    See above.

  8. #8
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: A whole Qt program as dynamic link lib? SOLVED

    So, with some help from Qt-interest I found my problem. It is possible to
    turn a normal Qt program into a dynlib just by changing in the .pro file the TEMPLATE = app into TEMPLATE = lib (and renaming the main function). My problem was a missing 'extern "C"' line. It is a bit strange, I would have expected that without it I would due to name mangling not be able to find any symbols in my lib, but not that it just segfaults while opening. Long before I am able to even try to access functions in the lib.

    Nevertheless, problem solved. I now have a .so file with a function start(int argc, char *argv[]), which can be called from other programs and which brings up my program fully functional.

    Customer is happy. I learned something.

Similar Threads

  1. How to use a Dynamic Link Library with QT / C++.
    By nivaldonicolau in forum Newbie
    Replies: 5
    Last Post: 29th April 2009, 14:05
  2. Dynamic link libraries
    By nareshqt in forum Qt Programming
    Replies: 6
    Last Post: 22nd April 2008, 06:20
  3. scope of dynamic variabe after program termination
    By babu198649 in forum General Programming
    Replies: 3
    Last Post: 6th February 2008, 13:09
  4. i want dynamic link my programm
    By coder1985 in forum Installation and Deployment
    Replies: 5
    Last Post: 19th November 2007, 10:59
  5. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19

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.