Creating a Qt static c++ library for non-Qt c++ application
-
Hello,
I created a static library in Qt 5.11 i have successfully generated lib.a and header file and used them in a Qt C++ project. Everything works fine.
Once i create a Non-Qt C++ project and include the library and header file, i get a compilation error " Qobject no such file or directory."Is there a way to create Qt static library for C++ (Non-Qt) application. I would later want to share this library for C++ application developed using Visual Studio/Other IDE.
-
You need the Qt headers when you include them in your library headers.
And there are very few Qt classes which work without a Qt event loop and even less working without a QCoreApplication. -
@sasanka said in Creating a Qt static c++ library for non-Qt c++ application:
I am only going to use the Network , QT core modules
This does not matter. Esp. the network module needs a running event loop.
-
@Christian-Ehrlicher
I built a static version of Qt 5.12.12 from the sources. I was also able to use this static build to compile the sources. But even after i created a static library out of this and when i am trying to include this library in a Non-Qt C++ project. I get compilation issues that displays QObject no found.So is there a procedure to use a custom made Qt Library for Non-Qt based C++ project.
If so could you point me out how i could achieve it. -
Sometimes I wonder if the people really read what we're writing...
If you have an header which includes QObject header file and want to use it in another library you have to provide the QObject header file there too. If you don't want this then don't include QObject in your header which basically means - don't use Qt at all.
This has nothing to do if a library is compiled static or shared - it's a basic thing - if you want to use a library you have to make sure you have access to all dependencies during built and runtime. -
@Christian-Ehrlicher or use the pimple idiom but that can make things pretty complicated depending on what the library originally offers as API.
-
@SGaist This will not work as the op exports a class derived from Qt (at least this is my guess) but yes, this can be an option. But as already discussed there are only a few Qt classes which work without a Q(Core)Application or a running event loop.
You can abstract this all away and add a wrapper class which convrts between Qt and plain c++ but this is cumbersome and still does not fix the event loop problem. -
@Christian-Ehrlicher said in Creating a Qt static c++ library for non-Qt c++ application:
@SGaist This will not work as the op exports a class derived from Qt (at least this is my guess) but yes, this can be an option. But as already discussed there are only a few Qt classes which work without a Q(Core)Application or a running event loop.
You can abstract this all away and add a wrapper class which convrts between Qt and plain c++ but this is cumbersome and still does not fix the event loop problem.100% agreed, it was just to propose a possible solution but it clearly makes things more complicated that way.