Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Using a Qt application as a library
I would like to develop a non-GUI C++ application that some functionality from a Qt application. Would it be possible to set up (for example) a CMake project that makes functions from a Qt application available in some other source code?
Appreciate this is quite a vague question, and would be happy to be more specific about what I have in mind if anyone has any ideas!
mrdebug last edited by
I think you should make a dll.
Pablo J. Rogina last edited by
@steadysupply so to understand, you want to create an application that would reuse functionality available already in a Qt application, right?
Ideally, such Qt application should be written in a way that GUI is separated from backend, and in this case you need to create a shared library (or DLL in Windows)with the backend features so it can be used by other applications.
If changes to source code of Qt application is not possible, how is such Qt application exposing the feature(s) you want to use? (i.e. provinding different command line arguments make the application do some things? or does the Qt application expose some REST API?)
I'm on Linux, so yes a shared library is what I'll need to create.
As far as I know, the Qt application I'm looking at doesn't offer a command line interface (or other programmable interface) for the features I'm interested in.
My question was really how would I start to go about creating a shared library from a Qt project that is designed to build an executable and not a shared library? The particular project in question is TeXstudio. I already asked a similar question over there: https://github.com/texstudio-org/texstudio/issues/30
I imagine it would be a question of porting the
qmakeconfig files to some other build system (I'll probably use CMake) ... is this something people do? Are there any resources out there discussing common fitfalls etc?
As i see, you biggest issue with using it as a LIB will be to spin the message pump if you plan
on letting the DLL show any GUI.
Thanks for your reply. I don't intend on having the shared library display any UI, I just want to use some features of a Qt application in the backend for a web site; in particular the LaTeX parsing and rendering capabilities of TeXstudio (which is a Qt application).
I'd like to hear from anyone who has done something similar, or has experience in porting a Qmake project to a more generic build system ...
Pablo J. Rogina last edited by
@steadysupply I guess that your main concern here should not be regarding the build system (which should be phase 2) but how/if the TeXstudio application was/is prepared from the very beginning for some parts of it to be compiled/built as a module, i.e. shared library.
From a quick look at its source code, it doesn't look so easy... In that case, another path could be to use just the source code itself for the part(s) you need. This approach could have the potential drawback of maintenance, although you may want to use the features of the version control tool (i.e.) to handle external submodules
Ok but if the parsing code uses anything Qt, it might not like to be created with no QApplication object.
QMake is a make maker. So its already generic. As much as CMake. If you look in the build folder, you will see it creates
a normale MakeFile.