qt5

This tool helps with finding Qt5 tools and libraries, and also provides syntactic sugar for using Qt5 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',
        )

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.

The detection uses pkg-config on Linux by default. To force static library detection use: QT5_XCOMPILE=1 QT5_FORCE_STATIC=1 waf configure

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.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]

Bases: waflib.Tools.cxx.cxx

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()]

hcode = 'nocode'
class waflib.Tools.qt5.trans_update(*k, **kw)[source]

Bases: waflib.Task.Task

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

color = 'BLUE'
hcode = '${QT_LUPDATE} ${SRC} -ts ${TGT}'
orig_run_str = '${QT_LUPDATE} ${SRC} -ts ${TGT}'
vars = ['QT_LUPDATE']
class waflib.Tools.qt5.XMLHandler[source]

Bases: xml.sax.handler.ContentHandler

Parses .qrc files

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
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

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]

Bases: waflib.Task.Task

Processes .qrc files

color = 'BLUE'
ext_out = ['.h']
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
hcode = '${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
orig_run_str = '${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
vars = ['QT_RCC', 'RCC_ST', 'tsk.rcname()']
class waflib.Tools.qt5.moc(*k, **kw)[source]

Bases: waflib.Task.Task

Creates .moc files

color = 'BLUE'
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
hcode = '${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'
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']
class waflib.Tools.qt5.ui5(*k, **kw)[source]

Bases: waflib.Task.Task

Processes .ui files

color = 'BLUE'
ext_out = ['.h']
hcode = '${QT_UIC} ${SRC} -o ${TGT}'
orig_run_str = '${QT_UIC} ${SRC} -o ${TGT}'
vars = ['QT_UIC']
class waflib.Tools.qt5.ts2qm(*k, **kw)[source]

Bases: waflib.Task.Task

Generates .qm files from .ts files

color = 'BLUE'
hcode = '${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'
orig_run_str = '${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'
vars = ['QT_LRELEASE', 'QT_LRELEASE_FLAGS']
class waflib.Tools.qt5.qm2rcc(*k, **kw)[source]

Bases: waflib.Task.Task

Generates .qrc files from .qm files

color = 'BLUE'
after = 'ts2qm'
run()[source]

Create a qrc file including the inputs

hcode = '\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'
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.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.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.Task 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.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.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.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 list created by doing parser_list + default_parser_list. The lists must contain the names of Python modules containing both a SAX parser and a create_parser function.

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.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: