2010-01-28

Use qmake include file pri

Qmake use pro file to define the project, while pri file is the include file for pro file. For example, the Qt state machine modual has a "qtstatemachine.pri" for external inclusion, you need to simply add

include(../../externals/qtstatemachine/src/qtstatemachine.pri)

into pro file to compily your code together with Qt state machine framework.
You can also optimise the modulise your code for external usage. Take an example, I have implemented a clock object by several classes. The classical pro file may looks like:

######## clock.pro #########################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += clStateMachine.h \
clThread.h

SOURCES += clStateMachine.cpp \
clThread.cpp \
main.cpp

include(../../externals/qtstatemachine/src/qtstatemachine.pri)
#######################################

Clearly, main.cpp is for the purpose of testing the object, the clock object is implemented in the other file. If you want to reuse this object in the other project, which may be located at the different path, you'd better to use pri file to modulize your object implmentation. Create a clock.pri at the same directory like:

######## clock.pri #########################
INCLUDEPATH += $$PWD
HEADERS += $$PWD/clStateMachine.h \
$$PWD/clThread.h

SOURCES += $$PWD/clStateMachine.cpp \
$$PWD/clThread.cpp

include($$PWD/../../externals/qtstatemachine/src/qtstatemachine.pri)

########################################

The old clock.pro is adapted like:

######### clock.pro (new) ###################
TEMPLATE = app
TARGET =
DEPENDPATH += .

# Input

SOURCES += main.cpp

include(./clock.pri)
########################################

Now you include your clock.pri in any other project by adding the following line into the pro of your project

include({relative or absolute path of clock.pri})

3 comments:

  1. Thank you! its helps me

    ReplyDelete
  2. Exactly what I was looking for, thank you.

    ReplyDelete
  3. Ironic that you posted this article in 2010 and everybody that posted comments found it in 2013, including me!

    Thanks, very nice explanation and it answered my question as well.

    ReplyDelete