This article explains how to use defineReplace in Qt. Pro files.

 

1. Read the explanatory documents on the official website first

Doc. Qt. IO/qt – 5 / qmake -…

 

1.1 Syntax Define func functions using defineReplace

defineReplace(func) 

{

}

1.2 func refs

$$func(11, 22, 33)

1.3 Return Value No matter what value is returned, parentheses are required. I can ignore it.

return (Hello world!)

 

1.4 Func capture parameters (1 to N)

defineReplace(func) 

{

ARG1 = $$1

ARG2 = $$2

ARG3 = $$3

}

 

2. Give examples

2.1 Create a public pri file, and use defineReplace to make the library file name suffix + D generated by debug:

common.pri

defineReplace(qtLibraryName) { unset(LIBRARY_NAME) LIBRARY_NAME = $$1 CONFIG(debug, debug|release) { ! debug_and_release|build_pass { mac:RET = $$member(LIBRARY_NAME, 0)_debug else:win32:RET = $$member(LIBRARY_NAME, 0)d}} isEmpty(RET):RET = $$LIBRARY_NAME return($$RET)} # MOC_DIR = temp/moc RCC_DIR = temp/ RCC UI_DIR = Temp/UI OBJECTS_DIR = temp/obj # Specifies the directory where the generated application is placed IDE_SOURCE_TREE = $$PWD #. Pro or. Pri The location of the file IDE_BUILD_TREE = $$IDE_SOURCE_TREE/.. / win32:CONFIG(debug, debug|release){ contains(DEFINES, WIN64) { DESTDIR = $$IDE_BUILD_TREE/_debug64 } else { DESTDIR = $$IDE_BUILD_TREE/_debug86 } } else:win32:CONFIG(release,  debug|release){ contains(DEFINES, WIN64) { DESTDIR = $$IDE_BUILD_TREE/_release64 } else { DESTDIR = $$IDE_BUILD_TREE/_release86 } } macx:CONFIG(debug, debug|release){ DESTDIR = $$IDE_BUILD_TREE/_debug64 } else:macx:CONFIG(release, debug|release){ DESTDIR = $$IDE_BUILD_TREE/_release64 }Copy the code

 

2.2 Create a new dynamic library project and write the pro file as follows:

include(.. /common.pri) QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TEMPLATE = lib TARGET = $$qtLibraryName(ribbonTabbar)Copy the code

In this case, debug generates the lib file names as Ribbontabbard. lib and Ribbontabbard.dll, with the suffix “D” automatically added.

 

Exe main program project, want to introduce the dynamic library, you can write in the pro file like this:

include(.. /common.pri) IDE_LIBRARY_PATH = $${DESTDIR} LIBS += -L$${IDE_LIBRARY_PATH} LIBS *= -L$$qtLibraryName(ribbonTabbar)Copy the code
  • LIBS *= and LIBS += mean the same thing.
  • -l indicates that it is followed by a folder that the project will add to the library file search path.
  • -l indicates that it is followed by the name of a library file. Lib,. DLL,. So,. A, do not need to add the suffix, just use the library before the semicolon part of the name.

 

3, sister

Qt Creator specifies temporary file generation directory (MOC_DIR/RCC_DIR, etc.) and PWD/OUT_PWD/.pro

Welcome to the companion article About relative paths in.pro files in the Qt Creator Project