qt5

This tool helps with finding Qt5 and Qt6 tools and libraries, and also provides syntactic sugar for using Qt5 and Qt6 tools.

The following snippet illustrates the tool usage:

def options(opt):
        opt.load('compiler_cxx qt5')

def configure(conf):
        conf.load('compiler_cxx qt5')

def build(bld):
        bld(
                features = 'qt5 cxx cxxprogram',
                uselib   = 'QT5CORE QT5GUI QT5OPENGL QT5SVG',
                source   = 'main.cpp textures.qrc aboutDialog.ui',
                target   = 'window',
        )

Alternatively the following snippet illustrates Qt6 tool usage:

def options(opt):
    opt.load('compiler_cxx qt5')

def configure(conf):
    conf.want_qt6 = True
    conf.load('compiler_cxx qt5')

def build(bld):
    bld(
        features = 'qt6 cxx cxxprogram',
        uselib   = 'QT6CORE QT6GUI QT6OPENGL QT6SVG',
        source   = 'main.cpp textures.qrc aboutDialog.ui',
        target   = 'window',
    )

Here, the UI description and resource files will be processed to generate code.

Usage

Load the “qt5” tool.

You also need to edit your sources accordingly:

  • the normal way of doing things is to have your C++ files include the .moc file. This is regarded as the best practice (and provides much faster compilations). It also implies that the include paths have beenset properly.

  • to have the include paths added automatically, use the following:

    from waflib.TaskGen import feature, before_method, after_method
    @feature('cxx')
    @after_method('process_source')
    @before_method('apply_incpaths')
    def add_includes_paths(self):
       incs = set(self.to_list(getattr(self, 'includes', '')))
       for x in self.compiled_tasks:
           incs.add(x.inputs[0].parent.path_from(self.path))
       self.includes = sorted(incs)
    

Note: another tool provides Qt processing that does not require .moc includes, see ‘playground/slow_qt/’.

A few options (–qt{dir,bin,…}) and environment variables (QT5_{ROOT,DIR,MOC,UIC,XCOMPILE}) allow finer tuning of the tool, tool path selection, etc; please read the source for more info. For Qt6 replace the QT5 prefix with QT6.

The detection uses pkg-config on Linux by default. The list of libraries to be requested to pkg-config is formulated by scanning in the QTLIBS directory (that can be passed via –qtlibs or by setting the environment variable QT5_LIBDIR or QT6_LIBDIR otherwise is derived by querying qmake for QT_INSTALL_LIBS directory) for shared/static libraries present. Alternatively the list of libraries to be requested via pkg-config can be set using the qt5_vars attribute, ie:

conf.qt5_vars = [‘Qt5Core’, ‘Qt5Gui’, ‘Qt5Widgets’, ‘Qt5Test’];

For Qt6 use the qt6_vars attribute.

This can speed up configuration phase if needed libraries are known beforehand, can improve detection on systems with a sparse QT5/Qt6 libraries installation (ie. NIX) and can improve detection of some header-only Qt modules (ie. Qt5UiPlugin).

To force static library detection use: QT5_XCOMPILE=1 QT5_FORCE_STATIC=1 waf configure

To use Qt6 set the want_qt6 attribute, ie:

conf.want_qt6 = True;

waflib.Tools.qt5.make_parser(parser_list=())[source]

Creates and returns a SAX parser.

Creates the first parser it is able to instantiate of the ones given in the iterable created by chaining parser_list and default_parser_list. The iterables must contain the names of Python modules containing both a SAX parser and a create_parser function.

class waflib.Tools.qt5.ContentHandler[source]

Interface for receiving logical document content events.

This is the main callback interface in SAX, and the one most important to applications. The order of events in this interface mirrors the order of the information in the document.

setDocumentLocator(locator)[source]

Called by the parser to give the application a locator for locating the origin of document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application’s business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.

startDocument()[source]

Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).

endDocument()[source]

Receive notification of the end of a document.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

startPrefixMapping(prefix, uri)[source]

Begin the scope of a prefix-URI Namespace mapping.

The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.

Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each-other: all startPrefixMapping events will occur before the corresponding startElement event, and all endPrefixMapping events will occur after the corresponding endElement event, but their order is not guaranteed.

endPrefixMapping(prefix)[source]

End the scope of a prefix-URI mapping.

See startPrefixMapping for details. This event will always occur after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.

startElement(name, attrs)[source]

Signals the start of an element in non-namespace mode.

The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

endElement(name)[source]

Signals the end of an element in non-namespace mode.

The name parameter contains the name of the element type, just as with the startElement event.

startElementNS(name, qname, attrs)[source]

Signals the start of an element in namespace mode.

The name parameter contains the name of the element type as a (uri, localname) tuple, the qname parameter the raw XML 1.0 name used in the source document, and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

The uri part of the name tuple is None for elements which have no namespace.

endElementNS(name, qname)[source]

Signals the end of an element in namespace mode.

The name parameter contains the name of the element type, just as with the startElementNS event.

characters(content)[source]

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

ignorableWhitespace(whitespace)[source]

Receive notification of ignorable whitespace in element content.

Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

processingInstruction(target, data)[source]

Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

skippedEntity(name)[source]

Receive notification of a skipped entity.

The Parser will invoke this method once for each entity skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties.

waflib.Tools.qt5.feature(*k)

Decorator that registers a task generator method that will be executed when the object attribute feature contains the corresponding key(s):

from waflib.TaskGen import feature
@feature('myfeature')
def myfunction(self):
        print('that is my feature!')
def build(bld):
        bld(features='myfeature')
Parameters

k (list of string) – feature names

waflib.Tools.qt5.after_method(*k)[source]

Decorator that registers a task generator method which will be executed after the functions of given name(s):

from waflib.TaskGen import feature, after
@feature('myfeature')
@after_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters

k (list of string) – method names

waflib.Tools.qt5.extension(*k)

Decorator that registers a task generator method which will be invoked during the processing of source files for the extension given:

from waflib import Task
class mytask(Task):
        run_str = 'cp ${SRC} ${TGT}'
@extension('.moo')
def create_maa_file(self, node):
        self.create_task('mytask', node, node.change_ext('.maa'))
def build(bld):
        bld(source='foo.moo')
waflib.Tools.qt5.before_method(*k)[source]

Decorator that registera task generator method which will be executed before the functions of given name(s):

from waflib.TaskGen import feature, before
@feature('myfeature')
@before_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters

k (list of string) – method names

waflib.Tools.qt5.conf(f)

Decorator: attach new configuration functions to waflib.Build.BuildContext and waflib.Configure.ConfigurationContext. The methods bound will accept a parameter named ‘mandatory’ to disable the configuration errors:

def configure(conf):
        conf.find_program('abc', mandatory=False)
Parameters

f (function) – method to bind

waflib.Tools.qt5.MOC_H = ['.h', '.hpp', '.hxx', '.hh']

File extensions associated to .moc files

waflib.Tools.qt5.EXT_RCC = ['.qrc']

File extension for the resource (.qrc) files

waflib.Tools.qt5.EXT_UI = ['.ui']

File extension for the user interface (.ui) files

waflib.Tools.qt5.EXT_QT5 = ['.cpp', '.cc', '.cxx', '.C']

File extensions of C++ files that may require a .moc processing

class waflib.Tools.qt5.qxx(*k, **kw)[source]

Each C++ file can have zero or several .moc files to create. They are known only when the files are scanned (preprocessor) To avoid scanning the c++ files each time (parsing C/C++), the results are retrieved from the task cache (bld.node_deps/bld.raw_deps). The moc tasks are also created dynamically during the build.

runnable_status()[source]

Compute the task signature to make sure the scanner was executed. Create the moc tasks by using waflib.Tools.qt5.qxx.add_moc_tasks() (if necessary), then postpone the task execution (there is no need to recompute the task signature).

create_moc_task(h_node, m_node)[source]

If several libraries use the same classes, it is possible that moc will run several times (Issue 1318) It is not possible to change the file names, but we can assume that the moc transformation will be identical, and the moc tasks can be shared in a global cache.

add_moc_tasks()[source]

Creates moc tasks by looking in the list of file dependencies bld.raw_deps[self.uid()]

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'nocode'

String representing an additional hash for the class representation

class waflib.Tools.qt5.trans_update(*k, **kw)[source]

Updates a .ts files from a list of C++ files

color = 'BLUE'

Color for the console display, see waflib.Logs.colors_lst

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'${QT_LUPDATE} ${SRC} -ts ${TGT}'

String representing an additional hash for the class representation

orig_run_str = '${QT_LUPDATE} ${SRC} -ts ${TGT}'
vars = ['QT_LUPDATE']

ConfigSet variables that should trigger a rebuild (class attribute used for waflib.Task.Task.sig_vars())

class waflib.Tools.qt5.XMLHandler[source]

Parses .qrc files

startElement(name, attrs)[source]

Signals the start of an element in non-namespace mode.

The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

endElement(name)[source]

Signals the end of an element in non-namespace mode.

The name parameter contains the name of the element type, just as with the startElement event.

characters(cars)[source]

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

__annotations__ = {}
waflib.Tools.qt5.create_rcc_task(self, node)[source]

Creates rcc and cxx tasks for .qrc files

waflib.Tools.qt5.create_uic_task(self, node)[source]

Create uic tasks for user interface .ui definition files

waflib.Tools.qt5.add_lang(self, node)[source]

Adds all the .ts file into self.lang

waflib.Tools.qt5.process_mocs(self)[source]

Task generator method

Processes MOC files included in headers:

def build(bld):
        bld.program(features='qt5', source='main.cpp', target='app', use='QT5CORE', moc='foo.h')

The build will run moc on foo.h to create moc_foo.n.cpp. The number in the file name is provided to avoid name clashes when the same headers are used by several targets.

Feature

qt5, qt6

waflib.Tools.qt5.apply_qt5(self)[source]

Task generator method

Adds MOC_FLAGS which may be necessary for moc:

def build(bld):
        bld.program(features='qt5', source='main.cpp', target='app', use='QT5CORE')

The additional parameters are:

Parameters
  • lang (list of waflib.Node.Node or string without the .ts extension) – list of translation files (*.ts) to process

  • update (bool) – whether to process the C++ files to update the *.ts files (use waf –translate)

  • langname (waflib.Node.Node or string without the .qrc extension) – if given, transform the *.ts files into a .qrc files to include in the binary file

Feature

qt5, qt6

waflib.Tools.qt5.cxx_hook(self, node)[source]

Re-maps C++ file extensions to the waflib.Tools.qt5.qxx task.

class waflib.Tools.qt5.rcc(*k, **kw)[source]

Processes .qrc files

color = 'BLUE'

Color for the console display, see waflib.Logs.colors_lst

ext_out = ['.h']

File extensions that objects of this task class may create

scan()[source]

Parse the .qrc files

quote_flag(x)[source]

Override Task.quote_flag. QT parses the argument files differently than cl.exe and link.exe

Parameters

x (string) – flag

Returns

quoted flag

Return type

string

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'

String representing an additional hash for the class representation

orig_run_str = '${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
sig_vars()

Used by waflib.Task.Task.signature(); it hashes waflib.Task.Task.env variables/values When overriding this method, and if scriptlet expressions are used, make sure to follow the code in waflib.Task.Task.compile_sig_vars() to enable dependencies on scriptlet results.

This method may be replaced on subclasses by the metaclass to force dependencies on scriptlet code.

vars = ['QT_RCC', 'RCC_ST', 'tsk.rcname()']

ConfigSet variables that should trigger a rebuild (class attribute used for waflib.Task.Task.sig_vars())

class waflib.Tools.qt5.moc(*k, **kw)[source]

Creates .moc files

color = 'BLUE'

Color for the console display, see waflib.Logs.colors_lst

quote_flag(x)[source]

Override Task.quote_flag. QT parses the argument files differently than cl.exe and link.exe

Parameters

x (string) – flag

Returns

quoted flag

Return type

string

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'

String representing an additional hash for the class representation

orig_run_str = '${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'
vars = ['DEFINES', 'INCPATHS', 'MOCCPPPATH_ST', 'MOCDEFINES_ST', 'MOC_FLAGS', 'MOC_ST', 'QT_MOC']

ConfigSet variables that should trigger a rebuild (class attribute used for waflib.Task.Task.sig_vars())

class waflib.Tools.qt5.ui5(*k, **kw)[source]

Processes .ui files

color = 'BLUE'

Color for the console display, see waflib.Logs.colors_lst

ext_out = ['.h']

File extensions that objects of this task class may create

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'${QT_UIC} ${SRC} -o ${TGT}'

String representing an additional hash for the class representation

orig_run_str = '${QT_UIC} ${SRC} -o ${TGT}'
vars = ['QT_UIC']

ConfigSet variables that should trigger a rebuild (class attribute used for waflib.Task.Task.sig_vars())

class waflib.Tools.qt5.ts2qm(*k, **kw)[source]

Generates .qm files from .ts files

color = 'BLUE'

Color for the console display, see waflib.Logs.colors_lst

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'

String representing an additional hash for the class representation

orig_run_str = '${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'
vars = ['QT_LRELEASE', 'QT_LRELEASE_FLAGS']

ConfigSet variables that should trigger a rebuild (class attribute used for waflib.Task.Task.sig_vars())

class waflib.Tools.qt5.qm2rcc(*k, **kw)[source]

Generates .qrc files from .qm files

color = 'BLUE'

Color for the console display, see waflib.Logs.colors_lst

after = 'ts2qm'

The instances of this class are executed after the instances of classes whose names are in this list

run()[source]

Create a qrc file including the inputs

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

hcode = b'\tdef run(self):\n\t\t"""Create a qrc file including the inputs"""\n\t\ttxt = \'\\n\'.join([\'<file>%s</file>\' % k.path_from(self.outputs[0].parent) for k in self.inputs])\n\t\tcode = \'<!DOCTYPE RCC><RCC version="1.0">\\n<qresource>\\n%s\\n</qresource>\\n</RCC>\' % txt\n\t\tself.outputs[0].write(code)\n'

String representing an additional hash for the class representation

waflib.Tools.qt5.configure(self)[source]

Besides the configuration options, the environment variable QT5_ROOT may be used to give the location of the qt5 libraries (absolute path).

The detection uses the program pkg-config through waflib.Tools.config_c.check_cfg()

waflib.Tools.qt5.find_qt5_binaries(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Detects Qt programs such as qmake, moc, uic, lrelease

waflib.Tools.qt5.set_qt5_libs_dir(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt5.find_single_qt5_lib(self, name, uselib, qtlibs, qtincludes, force_static)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt5.find_qt5_libraries(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt5.simplify_qt5_libs(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Since library paths make really long command-lines, and since everything depends on qtcore, remove the qtcore ones from qtgui, etc

waflib.Tools.qt5.add_qt5_rpath(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Defines rpath entries for Qt libraries

waflib.Tools.qt5.set_qt5_libs_to_check(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt5.set_qt5_defines(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt5.options(opt)[source]

Command-line options

Features defined in this module: