Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. DEFINES not visible in my project
QtWS25 Last Chance

DEFINES not visible in my project

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kloveridge
    wrote on last edited by
    #1

    I have a project that is composed of a main application and two personal libraries. I want to use some DEFINES in my project so I can put special code in when using this particular application. But I can't get my applicattion to "see" the defines. So this is the crux of the question.

    Let me briefly explain how the project fits together:

    The project has a main application and two of my own libraries. I am using a subdir file to "glue" it all together. The subdir .pro file has this:

    @QMAKE_CXXFLAGS_WARN_OFF -= -Wunused-parameter

    TEMPLATE = subdirs
    CONFIG += ordered
    DEFINES += IN_LOTUS_ENVIRONMENT

    QMAKE_CXXFLAGS_WARN_ON = ""
    QMAKE_CXXFLAGS_WARN_OFF += -Wunused-parameter

    SUBDIRS = ../Underworld ../EngineOGL ../Lotus@

    The application .pro file looks like this:

    @QT += core gui opengl widgets network

    TARGET = Lotus
    TEMPLATE = app
    CONFIG += c++11

    INCLUDEPATH = ..

    SOURCES += main.cpp
    mainwindow.cpp
    ...

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Underworld/release/ -lUnderworld
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../Underworld/debug/ -lUnderworld
    else:unix: LIBS += -L$$OUT_PWD/../Underworld/ -lUnderworld

    INCLUDEPATH += $$PWD/../Underworld
    DEPENDPATH += $$PWD/../Underworld

    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/release/libUnderworld.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/debug/libUnderworld.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/release/Underworld.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/debug/Underworld.lib
    else:unix: PRE_TARGETDEPS += $$OUT_PWD/../Underworld/libUnderworld.a

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../EngineOGL/release/ -lEngineOGL
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../EngineOGL/debug/ -lEngineOGL
    else:unix: LIBS += -L$$OUT_PWD/../EngineOGL/ -lEngineOGL@

    You will notice in the subdir .pro file I defined a variable called: IN_LOTUS_ENVIRONMENT.

    But nothing responds to the DEFINE. Here's a typical example of what I need to do:

    @#ifdef IN_LOTUS_ENVIRONMENT
    uw::appinterface->informDisplayChanged();
    qDebug() << "Hi there!";
    #endif@

    This snippet of code, I am putting in one of the libraries. And it doesn't work. I'm sure its my ignorance using #define. I would appreciate any insights anyone has.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should either have them in a pri file that you include when needed or in a .qmake.conf file in the root of your project if you are using Qt 5

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rondog
        wrote on last edited by
        #3

        It might need to be inside each project file that uses it. Maybe a shared .PRI file with the define statement:

        shared.pri
        @
        DEFINES += IN_LOTUS_ENVIRONMENT
        // other 'common' items
        @

        application.pro (assuming shared.pri is one directory up)
        @
        include( ../shared.pri )

        TARGET = Lotus
        TEMPLATE = app
        CONFIG += c++11
        ...
        @

        and at the top of the project
        @
        QMAKE_CXXFLAGS_WARN_OFF -= -Wunused-parameter

        TEMPLATE = subdirs
        CONFIG += ordered
         
        QMAKE_CXXFLAGS_WARN_ON = ""
        QMAKE_CXXFLAGS_WARN_OFF += -Wunused-parameter
         
        SUBDIRS = ../Underworld ../EngineOGL ../Lotus
        

        @

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kloveridge
          wrote on last edited by
          #4

          This solves part of the problem. My application.pro file now includes:

          @include (shared.pri)@

          I can see the define IN_LOTUS_ENVIRONMENT in the main application. But my two libraries can't see it still.

          So if I go into my Underground library, the define isn't visible. I conceptually must not understand how DEFINES work. I figured if I put it in the top file, it would disseminate out to everything hanging off the project (which it does in the files directly associated with the application). But apparently, my libraries are independent entities unaware of the top file.

          The whole point of this is if my libraries are attached to a particular application, I wanted certain chunks of code to run. If I have to include the shared.pri file in the two libraries, it completely defeats the purpose of the DEFINE.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved