Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > e63754dc5af9f9ec95223fcea9485104 > files > 1430

python3-PyQt4-devel-4.8.3-2.fc14.x86_64.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QDeclarativeExtensionPlugin Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QDeclarativeExtensionPlugin Class Reference<br /><sup><sup>[<a href="qtdeclarative.html">QtDeclarative</a> module]</sup></sup></h1><p>The QDeclarativeExtensionPlugin class provides an abstract base
for custom QML extension plugins. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qdeclarativeextensionplugin.html#QDeclarativeExtensionPlugin">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qdeclarativeextensionplugin.html#initializeEngine">initializeEngine</a></b> (<i>self</i>, QDeclarativeEngine&#160;<i>engine</i>, str&#160;<i>uri</i>)</li><li><div class="fn" /><b><a href="qdeclarativeextensionplugin.html#registerTypes">registerTypes</a></b> (<i>self</i>, str&#160;<i>uri</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QDeclarativeExtensionPlugin class provides an abstract base
for custom QML extension plugins.</p>
<p>QDeclarativeExtensionPlugin is a plugin interface that makes it
possible to create QML extensions that can be loaded dynamically
into QML applications. These extensions allow custom QML types to
be made available to the QML engine.</p>
<p>To write a QML extension plugin:</p>
<ul>
<li>Subclass QDeclarativeExtensionPlugin, implement <a href="qdeclarativeextensionplugin.html#registerTypes">registerTypes</a>()
method to register types using <a href="qdeclarativeengine.html#qmlRegisterType">qmlRegisterType</a>(),
and export the class using the <a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>() macro</li>
<li>Write an appropriate project file for the plugin</li>
<li>Create a <a href="qdeclarativemodules.html#writing-a-qmldir-file">qmldir file</a> to
describe the plugin</li>
</ul>
<p>QML extension plugins can be used to provide either
application-specific or library-like plugins. Library plugins
should limit themselves to registering types, as any manipulation
of the engine's root context may cause conflicts or other issues in
the library user's code.</p>
<a id="an-example" name="an-example" />
<h3>An example</h3>
<p>Suppose there is a new <tt>TimeModel</tt> C++ class that should
be made available as a new QML element. It provides the current
time through <tt>hour</tt> and <tt>minute</tt> properties, like
this:</p>
<pre class="highlightedCode brush: cpp">
 class TimeModel : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(int hour READ hour NOTIFY timeChanged)
     Q_PROPERTY(int minute READ minute NOTIFY timeChanged)
     ...
</pre>
<p>To make this class available as a QML type, create a plugin that
registers this type with a specific <a href="qdeclarativemodules.html#qml-modules">module</a> using <a href="qdeclarativeengine.html#qmlRegisterType">qmlRegisterType</a>().
For this example the plugin module will be named
<tt>com.nokia.TimeExample</tt> (as defined in the project file
further below).</p>
<pre class="highlightedCode brush: cpp">
 class QExampleQmlPlugin : public QDeclarativeExtensionPlugin
 {
     Q_OBJECT
 public:
     void registerTypes(const char *uri)
     {
         Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample"));
         qmlRegisterType&lt;TimeModel&gt;(uri, 1, 0, "Time");
     }
 };

 Q_EXPORT_PLUGIN2(qmlqtimeexampleplugin, QExampleQmlPlugin);
</pre>
<p>This registers the <tt>TimeModel</tt> class with the 1.0 version
of this plugin library, as a QML type called <tt>Time</tt>. The
Q_ASSERT statement ensures the module is imported correctly by any
QML components that use this plugin.</p>
<p>The project file defines the project as a plugin library and
specifies it should be built into the
<tt>com/nokia/TimeExample</tt> directory:</p>
<pre class="highlightedCode brush: cpp">
 TEMPLATE = lib
 CONFIG += qt plugin
 QT += declarative

 DESTDIR = com/nokia/TimeExample
 TARGET = qmlqtimeexampleplugin
 ...
</pre>
<p>Finally, a <a href="qdeclarativemodules.html#writing-a-qmldir-file">qmldir file</a> is
required in the <tt>com/nokia/TimeExample</tt> directory that
describes the plugin. This directory includes a <tt>Clock.qml</tt>
file that should be bundled with the plugin, so it needs to be
specified in the <tt>qmldir</tt> file:</p>
<pre class="highlightedCode brush: cpp">
 Clock 1.0 Clock.qml
 plugin qmlqtimeexampleplugin
</pre>
<p>Once the project is built and installed, the new <tt>Time</tt>
element can be used by any QML component that imports the
<tt>com.nokia.TimeExample</tt> module:</p>
<pre class="highlightedCode brush: cpp">
 import com.nokia.TimeExample 1.0 // import types from the plugin

 Clock { // this class is defined in QML (com/nokia/TimeExample/Clock.qml)

     Time { // this class is defined in C++ (plugin.cpp)
         id: time
     }

     hours: time.hour
     minutes: time.minute
 }
</pre>
<p>The full source code is available in the <a href="declarative-cppextensions-plugins.html">plugins example</a>.</p>
<p>The <a href="qml-extending-tutorial-index.html">Tutorial:
Writing QML extensions with C++</a> also contains a chapter on
creating QML plugins.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QDeclarativeExtensionPlugin" />QDeclarativeExtensionPlugin.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a QML extension plugin with the given
<i>parent</i>.</p>
<p>Note that this constructor is invoked automatically by the
<a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>()
macro, so there is no need for calling it explicitly.</p>


<h3 class="fn"><a name="initializeEngine" />QDeclarativeExtensionPlugin.initializeEngine (<i>self</i>, <a href="qdeclarativeengine.html">QDeclarativeEngine</a>&#160;<i>engine</i>, str&#160;<i>uri</i>)</h3><p>Initializes the extension from the <i>uri</i> using the
<i>engine</i>. Here an application plugin might, for example,
expose some data or objects to QML, as context properties on the
engine's root context.</p>


<h3 class="fn"><a name="registerTypes" />QDeclarativeExtensionPlugin.registerTypes (<i>self</i>, str&#160;<i>uri</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Registers the QML types in the given <i>uri</i>. Subclasses
should implement this to call <a href="qdeclarativeengine.html#qmlRegisterType">qmlRegisterType</a>() for
all types which are provided by the extension plugin.</p>
<p>The <i>uri</i> is an identifier for the plugin generated by the
QML engine based on the name and path of the extension's plugin
library.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.8.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2011</td><td align="right" width="25%">Qt&#160;4.7.1</td></tr></table></div></address></body></html>