File: incompatibilities.html

package info (click to toggle)
python-qt4 4.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 34,432 kB
  • sloc: python: 34,126; cpp: 11,938; xml: 290; makefile: 223; php: 27
file content (308 lines) | stat: -rw-r--r-- 21,653 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Potential Incompatibilities with Earlier Versions &mdash; PyQt 4.9.3 Reference Guide</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '4.9.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/logo_tn.ico"/>
    <link rel="top" title="PyQt 4.9.3 Reference Guide" href="index.html" />
    <link rel="next" title="Installing PyQt" href="installation.html" />
    <link rel="prev" title="Introduction" href="introduction.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installing PyQt"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="introduction.html" title="Introduction"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">PyQt 4.9.3 Reference Guide</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="potential-incompatibilities-with-earlier-versions">
<h1>Potential Incompatibilities with Earlier Versions<a class="headerlink" href="#potential-incompatibilities-with-earlier-versions" title="Permalink to this headline">¶</a></h1>
<div class="section" id="pyqt-v4-9-2">
<h2>PyQt v4.9.2<a class="headerlink" href="#pyqt-v4-9-2" title="Permalink to this headline">¶</a></h2>
<div class="section" id="qpynullvariant">
<h3>QPyNullVariant<a class="headerlink" href="#qpynullvariant" title="Permalink to this headline">¶</a></h3>
<p>In previous versions a <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> would always evaluate to <tt class="docutils literal"><span class="pre">True</span></tt>
when converted to a bool.</p>
<p>In this version a <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> will always evaluate to <tt class="docutils literal"><span class="pre">False</span></tt> when
converted to a bool.  This makes it behave like <tt class="docutils literal"><span class="pre">None</span></tt> in these
circumstances.</p>
</div>
</div>
<div class="section" id="pyqt-v4-8-3">
<h2>PyQt v4.8.3<a class="headerlink" href="#pyqt-v4-8-3" title="Permalink to this headline">¶</a></h2>
<div class="section" id="sql-models">
<h3>SQL Models<a class="headerlink" href="#sql-models" title="Permalink to this headline">¶</a></h3>
<p>In previous versions, when using v2 of the QVariant API (the default for Python
v3), there was no way to represent a null <tt class="docutils literal"><span class="pre">QVariant</span></tt>.  Therefore when reading
values of certain types from an SQL model it was impossible to distinguish
between, for example, a null integer and an integer with the value zero.</p>
<p>In this version the <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> class is used to represent a null
QVariant.  Therefore the object read from an SQL model may now be a
<tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> instance.</p>
<p>A null <tt class="docutils literal"><span class="pre">QVariant</span></tt> is only converted to a <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> if the underlying
C++ type of the <tt class="docutils literal"><span class="pre">QVariant</span></tt> cannot be tested for null, i.e. it does not
implement an <tt class="docutils literal"><span class="pre">isNull()</span></tt> method.  This ensures that existing code that uses
non-SQL models will continue to work unchanged.</p>
</div>
</div>
<div class="section" id="pyqt-v4-8">
<h2>PyQt v4.8<a class="headerlink" href="#pyqt-v4-8" title="Permalink to this headline">¶</a></h2>
<div class="section" id="qvariantlist">
<h3>QVariantList<a class="headerlink" href="#qvariantlist" title="Permalink to this headline">¶</a></h3>
<p>In previous versions PyQt would always try and convert a Python list to a
<tt class="docutils literal"><span class="pre">QVariantList</span></tt>.  In this version PyQt will first try to convert it to a
<tt class="docutils literal"><span class="pre">QVariant</span></tt> containing a <tt class="docutils literal"><span class="pre">QList&lt;QObject</span> <span class="pre">*&gt;</span></tt>, but only if
<tt class="docutils literal"><span class="pre">QList&lt;QObject</span> <span class="pre">*&gt;</span></tt> has been registered with Qt as a meta-type.</p>
<p>Normally it is only the <tt class="xref py py-mod docutils literal"><span class="pre">QtDeclarative</span></tt> module that registers this
meta-type and so the behaviour of existing applications should be unchanged.
It is possible however that you might observe different conversion behaviour
after importing the <tt class="xref py py-mod docutils literal"><span class="pre">QtDeclarative</span></tt> module.</p>
</div>
</div>
<div class="section" id="pyqt-v4-7-4">
<h2>PyQt v4.7.4<a class="headerlink" href="#pyqt-v4-7-4" title="Permalink to this headline">¶</a></h2>
<div class="section" id="pyqtsignal-with-dict-and-list">
<h3><a class="reference internal" href="new_style_signals_slots.html#PyQt4.QtCore.pyqtSignal" title="PyQt4.QtCore.pyqtSignal"><tt class="xref py py-func docutils literal"><span class="pre">pyqtSignal()</span></tt></a> with dict and list<a class="headerlink" href="#pyqtsignal-with-dict-and-list" title="Permalink to this headline">¶</a></h3>
<p>In previous versions a Qt signal defined using
<a class="reference internal" href="new_style_signals_slots.html#PyQt4.QtCore.pyqtSignal" title="PyQt4.QtCore.pyqtSignal"><tt class="xref py py-func docutils literal"><span class="pre">pyqtSignal()</span></tt></a> that had an argument specified as a dict then,
when emitting a value, PyQt would try and convert the value to a
<tt class="docutils literal"><span class="pre">QVariantMap</span></tt> if possible.  If it wasn&#8217;t possible, normally because the dict
had non-string keys, then the value would be left as a dict object.</p>
<p>In this version PyQt will not attempt to convert the value to a <tt class="docutils literal"><span class="pre">QVariantMap</span></tt>
and will always leave it as a dict object.  If you want the value to be
converted to a <tt class="docutils literal"><span class="pre">QVariantMap</span></tt> then define the signal argument as
<tt class="docutils literal"><span class="pre">'QVariantMap'</span></tt>.</p>
<p>The same applies to conversions between lists and <tt class="docutils literal"><span class="pre">QVariantList</span></tt>.</p>
</div>
</div>
<div class="section" id="pyqt-v4-7-1">
<h2>PyQt v4.7.1<a class="headerlink" href="#pyqt-v4-7-1" title="Permalink to this headline">¶</a></h2>
<div class="section" id="qvariant">
<h3>QVariant<a class="headerlink" href="#qvariant" title="Permalink to this headline">¶</a></h3>
<p>This version introduces a slight incompatibility in the conversion between
sub-classes of standard Python types and <tt class="docutils literal"><span class="pre">QVariant</span></tt>.</p>
<p>Take, for example, the following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">PyQt4.QtCore</span> <span class="kn">import</span> <span class="n">QVariant</span>

<span class="k">class</span> <span class="nc">MyFloat</span><span class="p">(</span><span class="nb">float</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="n">myfloat</span> <span class="o">=</span> <span class="n">MyFloat</span><span class="p">(</span><span class="mf">5.0</span><span class="p">)</span>
<span class="n">variant</span> <span class="o">=</span> <span class="n">QVariant</span><span class="p">(</span><span class="n">myfloat</span><span class="p">)</span>
</pre></div>
</div>
<p>With this version of PyQt <tt class="docutils literal"><span class="pre">myfloat</span></tt> will be converted in such a way as to
preserve any additional attributes (including methods) and will not be
converted to a C++ <tt class="docutils literal"><span class="pre">double</span></tt>.  In other words, the following assertions are
true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">!=</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Double</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="ow">is</span> <span class="n">myfloat</span><span class="p">)</span>
</pre></div>
</div>
<p>Prior to this version <tt class="docutils literal"><span class="pre">myfloat</span></tt> would be converted to a C++ <tt class="docutils literal"><span class="pre">double</span></tt>.  In
other words, the following assertions would be true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">==</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Double</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="o">==</span> <span class="n">myfloat</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">())</span> <span class="ow">is</span> <span class="nb">float</span><span class="p">)</span>
</pre></div>
</div>
<p>The same change also affects objects that implement the sequence protocol.
Prior to this version such an object would be converted to a <tt class="docutils literal"><span class="pre">QVariantList</span></tt>
which would mean that it was converted back to a Python <tt class="docutils literal"><span class="pre">list</span></tt> rather than to
the original type.</p>
</div>
</div>
<div class="section" id="pyqt-v4-5">
<h2>PyQt v4.5<a class="headerlink" href="#pyqt-v4-5" title="Permalink to this headline">¶</a></h2>
<div class="section" id="id1">
<h3>QVariant<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>This version introduces a slight incompatibility in the conversion between
Python sub-classes of certain Qt classes and <tt class="docutils literal"><span class="pre">QVariant</span></tt>.  The Qt classes
affected are those that <tt class="docutils literal"><span class="pre">QVariant</span></tt> has explicit support for, e.g. <tt class="docutils literal"><span class="pre">QSize</span></tt>,
<tt class="docutils literal"><span class="pre">QBitmap</span></tt>.</p>
<p>Take, for example, the following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">PyQt4.QtCore</span> <span class="kn">import</span> <span class="n">QSize</span><span class="p">,</span> <span class="n">QVariant</span>

<span class="k">class</span> <span class="nc">MySize</span><span class="p">(</span><span class="n">QSize</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="n">mysize</span> <span class="o">=</span> <span class="n">MySize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="n">variant</span> <span class="o">=</span> <span class="n">QVariant</span><span class="p">(</span><span class="n">mysize</span><span class="p">)</span>
</pre></div>
</div>
<p>With this version of PyQt <tt class="docutils literal"><span class="pre">mysize</span></tt> will be converted in such a way as to
preserve any additional attributes (including methods) and will not be
converted to a C++ <tt class="docutils literal"><span class="pre">QSize</span></tt> instance.  In other words, the following
assertions are true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">!=</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Size</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="ow">is</span> <span class="n">mysize</span><span class="p">)</span>
</pre></div>
</div>
<p>Prior to this version <tt class="docutils literal"><span class="pre">mysize</span></tt> would be converted to a C++ <tt class="docutils literal"><span class="pre">QSize</span></tt>
instance.  In other words, the following assertions would be true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">==</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Size</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="o">==</span> <span class="n">mysize</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">())</span> <span class="ow">is</span> <span class="n">QSize</span><span class="p">)</span>
</pre></div>
</div>
<p>It is hoped that this change of behaviour will not have a significant impact.
However if you need the old behaviour then simply create a copy of your
sub-class instance using the base class constructor as shown below:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">variant</span> <span class="o">=</span> <span class="n">QVariant</span><span class="p">(</span><span class="n">QSize</span><span class="p">(</span><span class="n">mysize</span><span class="p">))</span>
</pre></div>
</div>
<p>A similar issue also affects the conversion of the Python <tt class="docutils literal"><span class="pre">datetime</span></tt>,
<tt class="docutils literal"><span class="pre">date</span></tt> and <tt class="docutils literal"><span class="pre">time</span></tt> types to <tt class="docutils literal"><span class="pre">QVariant</span></tt>.  These are no longer converted to
the corresponding <tt class="docutils literal"><span class="pre">QDateTime</span></tt>, <tt class="docutils literal"><span class="pre">QDate</span></tt> and <tt class="docutils literal"><span class="pre">QTime</span></tt> classes.  The values
can be retrieved using <tt class="docutils literal"><span class="pre">QVariant.toPyObject()</span></tt>.  Again, the old behaviour can
be achieved using an explicit conversion to the Qt class before converting to
<tt class="docutils literal"><span class="pre">QVariant</span></tt>.</p>
<p>A further incompatible change is the handling of Python sub-classes of
<tt class="docutils literal"><span class="pre">QObject</span></tt>.  In previous versions <tt class="docutils literal"><span class="pre">QVariant.userType()</span></tt> would return an
internal type and an extra reference would be kept to the Python object.  In
the current version <tt class="docutils literal"><span class="pre">QVariant.userType()</span></tt> will correctly return
<tt class="docutils literal"><span class="pre">QMetaType.QObjectStar</span></tt> (or <tt class="docutils literal"><span class="pre">QMetaType.QWidgetStar</span></tt>) but an extra
reference to the Python object is not kept.  To avoid a potential crash you
should ensure that you keep a separate reference to the Python object, either
explicitly or implicitly by giving it a parent.</p>
</div>
<div class="section" id="pyrcc4-support-for-python-v3">
<h3><strong class="program">pyrcc4</strong> Support for Python v3<a class="headerlink" href="#pyrcc4-support-for-python-v3" title="Permalink to this headline">¶</a></h3>
<p><strong class="program">pyrcc4</strong> will now generate code for Python v3 when the new
<a class="reference internal" href="resources.html#cmdoption-pyrcc4-py3"><em class="xref std std-option">-py3</em></a> command line option is used.  The generated code
will also work with Python v2.6 and later.</p>
<p>By default <strong class="program">pyrcc4</strong> will generate code for all Python v2 versions but
you should use the new <a class="reference internal" href="resources.html#cmdoption-pyrcc4-py2"><em class="xref std std-option">-py2</em></a> command line option to
enforce this in case the default is changed in the future.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/logo.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Potential Incompatibilities with Earlier Versions</a><ul>
<li><a class="reference internal" href="#pyqt-v4-9-2">PyQt v4.9.2</a><ul>
<li><a class="reference internal" href="#qpynullvariant">QPyNullVariant</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pyqt-v4-8-3">PyQt v4.8.3</a><ul>
<li><a class="reference internal" href="#sql-models">SQL Models</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pyqt-v4-8">PyQt v4.8</a><ul>
<li><a class="reference internal" href="#qvariantlist">QVariantList</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pyqt-v4-7-4">PyQt v4.7.4</a><ul>
<li><a class="reference internal" href="#pyqtsignal-with-dict-and-list"><tt class="docutils literal"><span class="pre">pyqtSignal()</span></tt> with dict and list</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pyqt-v4-7-1">PyQt v4.7.1</a><ul>
<li><a class="reference internal" href="#qvariant">QVariant</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pyqt-v4-5">PyQt v4.5</a><ul>
<li><a class="reference internal" href="#id1">QVariant</a></li>
<li><a class="reference internal" href="#pyrcc4-support-for-python-v3"><strong class="program">pyrcc4</strong> Support for Python v3</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="introduction.html"
                        title="previous chapter">Introduction</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="installation.html"
                        title="next chapter">Installing PyQt</a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installing PyQt"
             >next</a> |</li>
        <li class="right" >
          <a href="introduction.html" title="Introduction"
             >previous</a> |</li>
        <li><a href="index.html">PyQt 4.9.3 Reference Guide</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2011 Riverbank Computing Limited.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>