qt4

Support for the Qt4 libraries and tools:

def options(opt):
        opt.load('compiler_cxx qt4')
def configure(conf):
        conf.load('compiler_cxx qt4')
        conf.env.append_value('CXXFLAGS', ['-g']) # test
def build(bld):
        bld(
                features = 'qt4 cxx cxxprogram',
                uselib   = 'QTCORE QTGUI QTOPENGL QTSVG',
                source   = 'main.cpp textures.qrc aboutDialog.ui',
                target   = 'window',
        )

The C++ files must include the .moc files, which is regarded as the best practice (much faster compilations). This also implies that the include paths have to be set 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 = list(incs)

Another tool provides a Qt processing that does not require the moc includes. See http://code.google.com/p/waf/source/browse/trunk/playground/slow_qt/

class waflib.Tools.qt4.ContentHandler

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.

characters(content)

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.

endDocument()

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.

endElement(name)

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.

endElementNS(name, qname)

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.

endPrefixMapping(prefix)

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.

ignorableWhitespace(whitespace)

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.

The application must not attempt to read from the array outside of the specified range.

processingInstruction(target, data)

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.

setDocumentLocator(locator)

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.

skippedEntity(name)

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.

startDocument()

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

startElement(name, attrs)

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.

startElementNS(name, qname, attrs)

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.

startPrefixMapping(prefix, uri)

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.

waflib.Tools.qt4.MOC_H

File extensions associated to the .moc files

waflib.Tools.qt4.EXT_RCC

File extension for the resource (.qrc) files

waflib.Tools.qt4.EXT_UI

File extension for the user interface (.ui) files

waflib.Tools.qt4.EXT_QT4

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

class waflib.Tools.qt4.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.

scan()[source]

Re-use the C/C++ scanner, but remove the moc files from the dependencies

runnable_status()[source]

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

add_moc_tasks()[source]

Create the moc tasks by looking in bld.raw_deps[self.uid()]

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

Bases: waflib.Task.Task

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

class waflib.Tools.qt4.XMLHandler[source]

Bases: xml.sax.handler.ContentHandler

Parser for .qrc files

waflib.Tools.qt4.create_rcc_task(self, node)[source]

Create rcc and cxx tasks for .qrc files

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

hook for uic tasks

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

add all the .ts file into self.lang

waflib.Tools.qt4.apply_qt4(self)[source]

Task generator method

Add MOC_FLAGS which may be necessary for moc:

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

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 :

qt4

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

Re-map C++ file extensions to the waflib.Tools.qt4.qxx task.

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

Bases: waflib.Task.Task

Process .qrc files

scan()[source]

Parse the .qrc files

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

Bases: waflib.Task.Task

Create .moc files

class waflib.Tools.qt4.ui4(*k, **kw)[source]

Bases: waflib.Task.Task

Process .ui files

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

Bases: waflib.Task.Task

Create .qm files from .ts files

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

Bases: waflib.Task.Task

Transform .qm files into .rc files

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

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

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

waflib.Tools.qt4.find_qt4_binaries(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt4.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.qt4.find_qt4_libraries(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt4.feature(*k)

Decorator: register 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.qt4.after_method(*k)

Decorator: register 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.qt4.extension(*k)

Decorator: register 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.qt4.simplify_qt4_libs(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt4.add_qt4_rpath(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.qt4.set_qt4_libs_to_check(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

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

Command-line options

Features defined in this module:

Previous topic

glib2

Next topic

kde4

This Page