Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using Qt Headers on Static Library



  • I created a subdirs project. I have 2 subproject called "app" and "engine". engine is a static library, and i want to use it from my app. But I cannot include Qt libraries like "<QStack>" in engine.

    It works if I include in app but not in my static library?



  • @maydin

    How did you create the .pro-file for the static library?

    It should be similar to the .pro of your application. The main difference is sthat you are using a different template in there.
    You need to declare also all Qt modules required as in your .pro for template app.

    The subdirs template basically bundles a couple of .pro and allows to build at once. Therefore your .pro for teh static library has to be self-contained.



  • @koahnig

    Edit: I realized wizard removes core from pro file. When i added core to Qt by using Qt += core it worked. Now i have different problems like unresolved references.

    I created from Qt Creator inside. Right clicked to project, "New Subroject" and selected static library. I compared .pro files from other classic projects but couldn't find a huge different except template. I do not see any library that starts with Q if i want to include.
    Here is my .pro file for static lib:

    **QT       -= core gui**
    TARGET = engine
    TEMPLATE = lib
    CONFIG += staticlib
    CONFIG += c++11
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
            coreclass.cpp \
    
    HEADERS += \
            coreclass.h \
    
    unix {
        target.path = /usr/lib
        INSTALLS += target
    }
    

  • Lifetime Qt Champion

    Hi,

    @maydin said in Using Qt Headers on Static Library:

    QT -= core gui

    Since you remove core and gui, you won't be able to use any of Qt's classes provided by these module.


Log in to reply