Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > ba44e1fd5abf263d5d9b90c956e5dbf3 > files > 32

PyQt-2.5-1mdk.i586.rpm

<HTML
><HEAD
><TITLE
>General Limitations</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.61
"><LINK
REL="HOME"
TITLE="Python Bindings for Qt (v2.5)"
HREF="t1.html"><LINK
REL="PREVIOUS"
TITLE="Other PyQt Goodies"
HREF="x103.html"><LINK
REL="NEXT"
TITLE="Signal and Slot Support"
HREF="x169.html"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Python Bindings for Qt (v2.5)</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x103.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x169.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN116"
>General Limitations</A
></H1
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN118"
>Python Strings, Qt Strings and Unicode</A
></H2
><P
>Unicode support was added to Qt in v2.0 and to Python in v1.6.  In Qt, Unicode
support is implemented using the <TT
CLASS="LITERAL"
>QString</TT
> class.  It is
important to understand that <TT
CLASS="LITERAL"
>QString</TT
>s, Python string objects
and Python Unicode objects are all different but conversions between them are
automatic in many cases and easy to achieve manually when needed.</P
><P
>Whenever PyQt expects a <TT
CLASS="LITERAL"
>QString</TT
> as a function argument, a
Python string object or a Python Unicode object can be provided instead, and
PyQt will do the necessary conversion automatically.</P
><P
>You may also manually convert Python string and Unicode objects to
<TT
CLASS="LITERAL"
>QString</TT
>s by using the <TT
CLASS="LITERAL"
>QString</TT
> constructor
as demonstrated in the following code fragment.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>qs1 = QString('Converted Python string object')
qs2 = QString(u'Converted Python Unicode object')</PRE
></TD
></TR
></TABLE
><P
>In order to convert a <TT
CLASS="LITERAL"
>QString</TT
> to a Python string object use
the Python <TT
CLASS="LITERAL"
>str()</TT
> function.  Applying
<TT
CLASS="LITERAL"
>str()</TT
> to a null <TT
CLASS="LITERAL"
>QString</TT
> and an empty
<TT
CLASS="LITERAL"
>QString</TT
> both result in an empty Python string object.</P
><P
>In order to convert a <TT
CLASS="LITERAL"
>QString</TT
> to a Python Unicode object use
the Python <TT
CLASS="LITERAL"
>unicode()</TT
> function.  Applying
<TT
CLASS="LITERAL"
>unicode()</TT
> to a null <TT
CLASS="LITERAL"
>QString</TT
> and an empty
<TT
CLASS="LITERAL"
>QString</TT
> both result in an empty Python Unicode object.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN141"
>Access to Protected Member Functions</A
></H2
><P
>When an instance of a C++ class is not created from Python it is not possible
to access the protected member functions, or emit the signals, of that
instance.  Attempts to do so will raise a Python exception.  Also, any Python
methods corresponding to the instance's virtual member functions will never be
called.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN144"
>Garbage Collection</A
></H2
><P
>C++ does not garbage collect unreferenced class instances, whereas Python does.
In the following C++ fragment both colours exist even though the first can no
longer be referenced from within the program:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>c = QColor();
c = QColor();</PRE
></TD
></TR
></TABLE
><P
>In the corresponding Python fragment, the first colour is destroyed when
the second is assigned to <TT
CLASS="LITERAL"
>c</TT
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>c = QColor()
c = QColor()</PRE
></TD
></TR
></TABLE
><P
>In Python, each colour must be assigned to different names.  Typically this
is done within class definitions, so the code fragment would be something like:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>self.c1 = QColor()
self.c2 = QColor()</PRE
></TD
></TR
></TABLE
><P
>Sometimes a Qt class instance will maintain a pointer to another instance and
will eventually call the destructor of that second instance. The most common
example is that a <TT
CLASS="LITERAL"
>QObject</TT
> (and any of its sub-classes) keeps
pointers to its children and will automatically call their destructors. In
these cases, the corresponding Python object will also keep a reference to the
corresponding child objects.</P
><P
>So, in the following Python fragment, the first <TT
CLASS="LITERAL"
>QLabel</TT
> is
not destroyed when the second is assigned to <TT
CLASS="LITERAL"
>l</TT
> because the
parent <TT
CLASS="LITERAL"
>QWidget</TT
> still has a reference to it.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>p = QWidget()
l = QLabel('First label',p)
l = QLabel('Second label',p)</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN160"
>C++ Variables</A
></H2
><P
>Access to C++ variables is supported.  They are accessed as Python instance
variables.  For example:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>tab = QTab()
tab.label = "First Tab"
tab.r = QRect(10,10,75,30)</PRE
></TD
></TR
></TABLE
><P
>Global variables and static class variables are effectively read-only.  They
can be assigned to, but the underlying C++ variable will not be changed.  This
may change in the future.</P
><P
>Access to protected C++ class variables is not supported.  This may change in
the future.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN166"
>Multiple Inheritance</A
></H2
><P
>It is not possible to define a new Python class that sub-classes from more than
one Qt class.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x103.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="t1.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x169.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Other PyQt Goodies</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Signal and Slot Support</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>