##// END OF EJS Templates
updated docs...
florianlink -
r149:2c08e22f6b54
parent child
Show More
@@ -1,525 +1,532
1 1 #ifndef _PYTHONQTDOC_H
2 2 #define _PYTHONQTDOC_H
3 3
4 4 /*
5 5 *
6 6 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7 7 *
8 8 * This library is free software; you can redistribute it and/or
9 9 * modify it under the terms of the GNU Lesser General Public
10 10 * License as published by the Free Software Foundation; either
11 11 * version 2.1 of the License, or (at your option) any later version.
12 12 *
13 13 * This library is distributed in the hope that it will be useful,
14 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 16 * Lesser General Public License for more details.
17 17 *
18 18 * Further, this software is distributed without any warranty that it is
19 19 * free of the rightful claim of any third person regarding infringement
20 20 * or the like. Any license provided herein, whether implied or
21 21 * otherwise, applies only to this software file. Patent licenses, if
22 22 * any, provided herein do not apply to combinations of this program with
23 23 * other software, or any other product whatsoever.
24 24 *
25 25 * You should have received a copy of the GNU Lesser General Public
26 26 * License along with this library; if not, write to the Free Software
27 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 28 *
29 29 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30 30 * 28359 Bremen, Germany or:
31 31 *
32 32 * http://www.mevis.de
33 33 *
34 34 */
35 35
36 36 //----------------------------------------------------------------------------------
37 37 /*!
38 38 // \file PythonQtDoc.h
39 39 // \author Florian Link
40 40 // \author Last changed by $Author: florian $
41 41 // \date 2006-10
42 42 */
43 43 //----------------------------------------------------------------------------------
44 44
45 45 /*!
46 46 \if USE_GLOBAL_DOXYGEN_DOC
47 47 \page PythonQtPage PythonQt Overview
48 48 \else
49 49 \mainpage notitle
50 50 \endif
51 51
52 52 \image html PythonQt.jpg
53 53
54 54 \section Introduction
55 55
56 56 \b PythonQt is a dynamic <a href="http://www.python.org" target="_blank">
57 57 Python</a> binding for the <a href="http://qt.nokia.com" target="_blank">
58 58 Qt framework</a>.
59 59 It offers an easy way to embed the Python scripting language into
60 60 your C++ Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt 4.x.
61 61
62 62 The focus of PythonQt is on embedding Python into an existing C++ application, not on writing the whole
63 63 application completely in Python. If you want to write your whole application in Python,
64 64 you should use <a href="http://www.riverbankcomputing.co.uk/pyqt/" target="_blank">PyQt</a> or <a href="http://www.pyside.org" target="_blank">PySide</a> instead.
65 65
66 66 If you are looking for a simple way to embed Python objects into your C++/Qt Application
67 67 and to script parts of your application via Python, PythonQt is the way to go!
68 68
69 69 PythonQt is a stable library that was developed to make the
70 70 Image Processing and Visualization platform <a href="http://www.mevislab.de" target="_blank">MeVisLab</a>
71 71 scriptable from Python.
72 72
73 - \ref Features
74 - \ref Download
75 - \ref License
76 - \ref Developer
77 - \ref Building
78 - \ref Examples
79
73 80 \page Features Features
74 81
75 82 \section Builtin Built-in Features
76 83
77 84 The following are the built-in features of the PythonQt library:
78 85
79 86 - Access all \b slots, \b properties, children and registered enums of any QObject derived class from Python
80 87 - Connecting Qt Signals to Python functions (both from within Python and from C++)
81 88 - Easy wrapping of Python objects from C++ with smart, reference-counting PythonQtObjectPtr.
82 89 - Convenient conversions to/from QVariant for PythonQtObjectPtr.
83 90 - Wrapping of C++ objects (which are not derived from QObject) via PythonQtCppWrapperFactory
84 91 - Extending C++ and QObject derived classes with additional slots, static methods and constructors (see Decorators)
85 92 - StdOut/Err redirection to Qt signals instead of cout
86 93 - Interface for creating your own \c import replacement, so that Python scripts can be e.g. signed/verified before they are executed (PythonQtImportFileInterface)
87 94 - Mapping of plain-old-datatypes and ALL QVariant types to and from Python
88 95 - Support for wrapping of user QVariant types which are registerd via QMetaType
89 96 - Support for Qt namespace (with all enumerators)
90 97 - All PythonQt wrapped objects support the dir() statement, so that you can see easily which attributes a QObject, CPP object or QVariant has
91 98 - No preprocessing/wrapping tool needs to be started, PythonQt can script any QObject without prior knowledge about it (except for the MetaObject information from the \b moc)
92 99 - Multiple inheritance for C++ objects (e.g. a QWidget is derived from QObject and QPaintDevice, PythonQt will automatically cast a QWidget to a QPaintDevice when needed)
93 100 - Polymorphic downcasting (if e.g. PythonQt sees a QEvent, it can downcast it depending on the type(), so the Python e.g. sees a QPaintEvent instead of a plain QEvent)
94 101 - Deriving C++ objects from Python and overwriting virtual method with a Python implementation (requires usage of wrapper generator or manual work!)
95 102 - Extensible handler for Python/C++ conversion of complex types, e.g. mapping of QVector<SomeObject> to/from a Python array
96 103 - Setting of dynamic QObject properties via setProperty(), dynamic properties can be accessed for reading and writing like normal Python attributes (but creating a new property needs to be done with setProperty(), to distinguish from normal Python attributes)
97 104
98 105 \section FeaturesQtAll Features with wrapper generator
99 106
100 107 Thanks to the new wrapper generator, PythonQt now offers the additional PythonQt_QtAll library which wraps the complete Qt API, including all C++ classes and all non-slots on QObject derived classes.
101 108 This offers the following features:
102 109
103 110 - Complete Qt API wrapped and accessible
104 111 - The following modules are available as submodules of the PythonQt module:
105 112 - QtCore
106 113 - QtGui
107 114 - QtNetwork
108 115 - QtOpenGL
109 116 - QtSql
110 117 - QtSvg
111 118 - QtUiTools
112 119 - QtWebKit
113 120 - QtXml
114 121 - (QtXmlPatterns, QtScript, QtHelp, phonon, assistant, designer are currently not supported, this would require some additional effort on the code generator)
115 122 - For convenience, all classes are also available in the PythonQt.Qt module, for people who do not care in which module a class is located
116 123 - Any Qt class that has virtual methods can be easily derived from Python and the virtual methods can be reimplemented in Python (this feature is considered experimental!)
117 124 - Polymorphic downcasting on QEvent, QGraphicsItem, QStyleOption, ...
118 125 - Multiple inheritance support (e.g., QGraphicsTextItem is a QObject AND a QGraphicsItem, PythonQt will handle this well)
119 126
120 127 \section Comparison Comparison with PyQt/PySide
121 128
122 129 - PythonQt is not as pythonic as PyQt in many details (e.g. buffer protocol, pickling, translation support, ...) and it is mainly thought for embedding and intercommunication between Qt/Cpp and Python
123 130 - PythonQt allows to communicate in both directions, e.g., calling a Python object from C++ AND calling a C++ method from Python, while PyQt only handles the Python->C++ direction
124 131 - PythonQt offers properties as Python attributes, while PyQt offers them as setter/getter methods (e.g. QWidget.width is a property in PythonQt and a method in PyQt)
125 132 - PythonQt currently does not support instanceof checks for Qt classes, except for the exact match and derived Python classes
126 133 - QObject.emit to emit Qt signals from Python is not yet implemented but PythonQt allows to just emit a signal by calling it like a normal slot
127 134 - PythonQt does not (yet) offer to add new signals to Python/C++ objects and it does not yet support the newstyle PyQt signals (so you need to connect via C++ string signatures)
128 135 - Ownership of objects is a bit different in PythonQt, currently Python classes derived from a C++ class need to be manually referenced in Python to not get deleted too early (this will be fixed in a future version)
129 136 - QStrings are always converted to unicode Python objects, QByteArray always stays a QByteArray and can be converted using str()
130 137 - There are many details in the generated wrappers that could need some polishing, e.g., methods that use pointer arguments for additional return values could return a results tuple.
131 138 - Not all types of QList/QVector/QHash templates are supported, some Qt methods use those as arguments/return values (but you can add your own handlers to handle them if you need them).
132 139 - Probably there are lots of details that differ, I do not know PyQt that well to list them all.
133 140 - In the long run, PythonQt will consider using/extending PySide with the features of PythonQt to get rid of its own generator and typesystem files, alternatively the KDE Smoke generator might be used in the future (this has not yet been decided, the current PythonQt generator works well and there is no hurry to switch).
134 141
135 142 \page Download Download
136 143
137 144 PythonQt is hosted on <a href="http://sourceforge.net/projects/pythonqt/" target="_blank">SourceForge</a>.
138 145
139 146 You can download the source code as a tarball at http://sourceforge.net/projects/pythonqt/files/.
140 147 Alternatively you can get the latest version from the svn repository.
141 148
142 149 You can also browse the source code online via ViewVC: http://pythonqt.svn.sourceforge.net/viewvc/pythonqt/trunk/
143 150
144 151 \note We do not offer prebuilt binaries, since there are so many possible combinations of
145 152 platforms (Windows/Linux/MacOs), architectures (32/64 bit) and Python versions.
146 153
147 154 \page License License
148 155
149 156 PythonQt is distributed under the LGPL license, so it pairs well with the LGPL of the Qt 4.5 release and allows
150 157 to be used in commercial applications when following the LGPL 2.1 obligations.
151 158
152 159 The build system of PythonQt makes use of a modified version of the LGPL'ed QtScript generator,
153 160 located in the "generator" directory.
154 161
155 162 See http://qt.gitorious.org/qt-labs/qtscriptgenerator for details on the original project.
156 163 Thanks a lot to the QtJambi guys and the QtScript Generator project for the C++ parser and
157 164 Qt typesystem files!
158 165
159 166 The PythonQt wrappers generated by the generator located in the "generated_cpp" directory are free to be used without any licensing restrictions.
160 167
161 168 The generated wrappers are pre-generated and checked-in for Qt 4.6.1, so you only need to build and run the
162 169 generator when you want to build additional wrappers or you want to upgrade/downgrade to another Qt version.
163 170 You may use the generator to generate C++ bindings for your own C++ classes (e.g., to make them inheritable in Python),
164 171 but this is currently not documented and involves creating your own typesystem files (although the Qt Jambi examples might help you).
165 172
166 173
167 174 \page Developer Developer
168 175
169 176 \section Interface Interface
170 177
171 178 The main interface to PythonQt is the PythonQt singleton.
172 179 PythonQt needs to be initialized via PythonQt::init() once.
173 180 Afterwards you communicate with the singleton via PythonQt::self().
174 181 PythonQt offers a complete Qt binding, which
175 182 needs to be enabled via PythonQt_QtAll::init().
176 183
177 184
178 185 \section Datatype Datatype Mapping
179 186
180 187 The following table shows the mapping between Python and Qt objects:
181 188 <table>
182 189 <tr><th>Qt/C++</th><th>Python</th></tr>
183 190 <tr><td>bool</td><td>bool</td></tr>
184 191 <tr><td>double</td><td>float</td></tr>
185 192 <tr><td>float</td><td>float</td></tr>
186 193 <tr><td>char/uchar,int/uint,short,ushort,QChar</td><td>integer</td></tr>
187 194 <tr><td>long</td><td>integer</td></tr>
188 195 <tr><td>ulong,longlong,ulonglong</td><td>long</td></tr>
189 196 <tr><td>QString</td><td>unicode string</td></tr>
190 197 <tr><td>QByteArray</td><td>QByteArray wrapper</td></tr>
191 198 <tr><td>char*</td><td>str</td></tr>
192 199 <tr><td>QStringList</td><td>tuple of unicode strings</td></tr>
193 200 <tr><td>QVariantList</td><td>tuple of objects</td></tr>
194 201 <tr><td>QVariantMap</td><td>dict of objects</td></tr>
195 202 <tr><td>QVariant</td><td>depends on type, see below</td></tr>
196 203 <tr><td>QSize, QRect and all other standard Qt QVariants</td><td>variant wrapper that supports complete API of the respective Qt classes</td></tr>
197 204 <tr><td>OwnRegisteredMetaType</td><td>C++ wrapper, optionally with additional information/wrapping provided by registerCPPClass()</td></tr>
198 205 <tr><td>QList<AnyObject*></td><td>converts to a list of CPP wrappers</td></tr>
199 206 <tr><td>QVector<AnyObject*></td><td>converts to a list of CPP wrappers</td></tr>
200 207 <tr><td>EnumType</td><td>Enum wrapper derived from python integer</td></tr>
201 208 <tr><td>QObject (and derived classes)</td><td>QObject wrapper</td></tr>
202 209 <tr><td>C++ object</td><td>CPP wrapper, either wrapped via PythonQtCppWrapperFactory or just decorated with decorators</td></tr>
203 210 <tr><td>PyObject</td><td>PyObject</td></tr>
204 211 </table>
205 212
206 213 PyObject is passed as direct pointer, which allows to pass/return any Python object directly to/from
207 214 a Qt slot that uses PyObject* as its argument/return value.
208 215 QVariants are mapped recursively as given above, e.g. a dictionary can
209 216 contain lists of dictionaries of doubles.
210 217 All Qt QVariant types are implemented, PythonQt supports the complete Qt API for these object.
211 218
212 219 \section QObject QObject Wrapping
213 220
214 221 All classes derived from QObject are automatically wrapped with a python wrapper class
215 222 when they become visible to the Python interpreter. This can happen via
216 223 - the PythonQt::addObject() method
217 224 - when a Qt \b slot returns a QObject derived object to python
218 225 - when a Qt \b signal contains a QObject and is connected to a python function
219 226
220 227 It is important that you call PythonQt::registerClass() for any QObject derived class
221 228 that may become visible to Python, except when you add it via PythonQt::addObject().
222 229 This will register the complete parent hierachy of the registered class, so that
223 230 when you register e.g. a QPushButton, QWidget will be registered as well (and all intermediate
224 231 parents).
225 232
226 233 From Python, you can talk to the returned QObjects in a natural way by calling
227 234 their slots and receiving the return values. You can also read/write all
228 235 properties of the objects as if they where normal python properties.
229 236
230 237 In addition to this, the wrapped objects support
231 238 - className() - returns a string that reprents the classname of the QObject
232 239 - help() - shows all properties, slots, enums, decorator slots and constructors of the object, in a printable form
233 240 - delete() - deletes the object (use with care, especially if you passed the ownership to C++)
234 241 - connect(signal, function) - connect the signal of the given object to a python function
235 242 - connect(signal, qobject, slot) - connect the signal of the given object to a slot of another QObject
236 243 - disconnect(signal, function) - disconnect the signal of the given object from a python function
237 244 - disconnect(signal, qobject, slot) - disconnect the signal of the given object from a slot of another QObject
238 245 - children() - returns the children of the object
239 246 - setParent(QObject) - set the parent
240 247 - QObject* parent() - get the parent
241 248
242 249 The below example shows how to connect signals in Python:
243 250
244 251 \code
245 252 # define a signal handler function
246 253 def someFunction(flag):
247 254 print flag
248 255
249 256 # button1 is a QPushButton that has been added to Python via addObject()
250 257 # connect the clicked signal to a python function:
251 258 button1.connect("clicked(bool)", someFunction)
252 259
253 260 \endcode
254 261
255 262 \section CPP CPP Wrapping
256 263
257 264 You can create dedicated wrapper QObjects for any C++ class. This is done by deriving from PythonQtCppWrapperFactory
258 265 and adding your factory via addWrapperFactory().
259 266 Whenever PythonQt encounters a CPP pointer (e.g. on a slot or signal)
260 267 and it does not known it as a QObject derived class, it will create a generic CPP wrapper. So even unknown C++ objects
261 268 can be passed through Python. If the wrapper factory supports the CPP class, a QObject wrapper will be created for each
262 269 instance that enters Python. An alternative to a complete wrapper via the wrapper factory are decorators, see \ref Decorators
263 270
264 271 \section MetaObject Meta Object/Class access
265 272
266 273 For each known C++ class, PythonQt provides a Python class. These classes are visible
267 274 inside of the "PythonQt" python module or in subpackages if a package is given when the class is registered.
268 275
269 276 A Meta class supports:
270 277
271 278 - access to all declared enum values
272 279 - constructors
273 280 - static methods
274 281 - unbound non-static methods
275 282 - help() and className()
276 283
277 284 From within Python, you can import the module "PythonQt" to access these classes and the Qt namespace.
278 285
279 286 \code
280 287 from PythonQt import QtCore
281 288
282 289 # namespace access:
283 290 print QtCore.Qt.AlignLeft
284 291
285 292 # constructors
286 293 a = QtCore.QSize(12,13)
287 294 b = QtCore.QFont()
288 295
289 296 # static method
290 297 QtCore.QDate.currentDate()
291 298
292 299 # enum value
293 300 QtCore.QFont.UltraCondensed
294 301
295 302 \endcode
296 303
297 304 \section Decorators Decorator slots
298 305
299 306 PythonQt introduces a new generic approach to extend any wrapped QObject or CPP object with
300 307
301 308 - constructors
302 309 - destructors (for CPP objects)
303 310 - additional slots
304 311 - static slots (callable on both the Meta object and the instances)
305 312
306 313 The idea behind decorators is that we wanted to make it as easy as possible to extend
307 314 wrapped objects. Since we already have an implementation for invoking any Qt Slot from
308 315 Python, it looked promising to use this approach for the extension of wrapped objects as well.
309 316 This avoids that the PythonQt user needs to care about how Python arguments are mapped from/to
310 317 Qt when he wants to create static methods, constructors and additional member functions.
311 318
312 319 The basic idea about decorators is to create a QObject derived class that implements slots
313 320 which take one of the above roles (e.g. constructor, destructor etc.) via a naming convention.
314 321 These slots are then assigned to other classes via the naming convention.
315 322
316 323 - SomeClassName* new_SomeClassName(...) - defines a constructor for "SomeClassName" that returns a new object of type SomeClassName (where SomeClassName can be any CPP class, not just QObject classes)
317 324 - void delete_SomeClassName(SomeClassName* o) - defines a destructor, which should delete the passed in object o
318 325 - anything static_SomeClassName_someMethodName(...) - defines a static method that is callable on instances and the meta class
319 326 - anything someMethodName(SomeClassName* o, ...) - defines a slot that will be available on SomeClassName instances (and derived instances). When such a slot is called the first argument is the pointer to the instance and the rest of the arguments can be used to make a call on the instance.
320 327
321 328 The below example shows all kinds of decorators in action:
322 329
323 330 \code
324 331
325 332 // an example CPP object
326 333 class YourCPPObject {
327 334 public:
328 335 YourCPPObject(int arg1, float arg2) { a = arg1; b = arg2; }
329 336
330 337 float doSomething(int arg1) { return arg1*a*b; };
331 338
332 339 private:
333 340
334 341 int a;
335 342 float b;
336 343 };
337 344
338 345 // an example decorator
339 346 class ExampleDecorator : public QObject
340 347 {
341 348 Q_OBJECT
342 349
343 350 public slots:
344 351 // add a constructor to QSize that takes a QPoint
345 352 QSize* new_QSize(const QPoint& p) { return new QSize(p.x(), p.y()); }
346 353
347 354 // add a constructor for QPushButton that takes a text and a parent widget
348 355 QPushButton* new_QPushButton(const QString& text, QWidget* parent=NULL) { return new QPushButton(text, parent); }
349 356
350 357 // add a constructor for a CPP object
351 358 YourCPPObject* new_YourCPPObject(int arg1, float arg2) { return new YourCPPObject(arg1, arg2); }
352 359
353 360 // add a destructor for a CPP object
354 361 void delete_YourCPPObject(YourCPPObject* obj) { delete obj; }
355 362
356 363 // add a static method to QWidget
357 364 QWidget* static_QWidget_mouseGrabber() { return QWidget::mouseGrabber(); }
358 365
359 366 // add an additional slot to QWidget (make move() callable, which is not declared as a slot in QWidget)
360 367 void move(QWidget* w, const QPoint& p) { w->move(p); }
361 368
362 369 // add an additional slot to QWidget, overloading the above move method
363 370 void move(QWidget* w, int x, int y) { w->move(x,y); }
364 371
365 372 // add a method to your own CPP object
366 373 int doSomething(YourCPPObject* obj, int arg1) { return obj->doSomething(arg1); }
367 374 };
368 375
369 376 ...
370 377
371 378 PythonQt::self()->addDecorators(new ExampleDecorator());
372 379 PythonQt::self()->registerCPPClass("YourCPPObject");
373 380
374 381 \endcode
375 382
376 383 After you have registered an instance of the above ExampleDecorator, you can do the following from Python
377 384 (all these calls are mapped to the above decorator slots):
378 385
379 386 \code
380 387 from PythonQt import QtCore, QtGui, YourCPPObject
381 388
382 389 # call our new constructor of QSize
383 390 size = QtCore.QSize(QPoint(1,2));
384 391
385 392 # call our new QPushButton constructor
386 393 button = QtGui.QPushButton("sometext");
387 394
388 395 # call the move slot (overload1)
389 396 button.move(QPoint(0,0))
390 397
391 398 # call the move slot (overload2)
392 399 button.move(0,0)
393 400
394 401 # call the static method
395 402 grabber = QtGui.QWidget.mouseWrapper();
396 403
397 404 # create a CPP object via constructor
398 405 yourCpp = YourCPPObject(1,11.5)
399 406
400 407 # call the wrapped method on CPP object
401 408 print yourCpp.doSomething(1);
402 409
403 410 # destructor will be called:
404 411 yourCpp = None
405 412
406 413 \endcode
407 414
408 415 \page Building Building
409 416
410 417 PythonQt requires at least Qt 4.6.1 (for earlier Qt versions, you will need to run the pythonqt_gerenator, Qt 4.3 is the absolute minimum) and Python 2.5.x or 2.6.x on Windows, Linux and MacOS X. It has not yet been tested with Python 3.x, but it should only require minor changes.
411 418 To compile PythonQt, you will need a python developer installation which includes Python's header files and
412 419 the python2x.[lib | dll | so | dynlib].
413 420 The build scripts a currently set to use Python 2.6.
414 421 You may need to tweak the \b build/python.prf file to set the correct Python includes and libs on your system.
415 422
416 423 \subsection Windows
417 424
418 425 On Windows, the (non-source) Python Windows installer can be used.
419 426 Make sure that you use the same compiler, the current Python distribution is built
420 427 with Visual Studio 2003. If you want to use another compiler, you will need to build
421 428 Python yourself, using your compiler.
422 429
423 430 To build PythonQt, you need to set the environment variable \b PYTHON_PATH to point to the root
424 431 dir of the python installation and \b PYTHON_LIB to point to
425 432 the directory where the python lib file is located.
426 433
427 434 When using the prebuild Python installer, this will be:
428 435
429 436 \code
430 437 > set PYTHON_PATH = c:\Python26
431 438 > set PYTHON_LIB = c:\Python26\libs
432 439 \endcode
433 440
434 441 When using the python sources, this will be something like:
435 442
436 443 \code
437 444 > set PYTHON_PATH = c:\yourDir\Python-2.6.1\
438 445 > set PYTHON_LIB = c:\yourDir\Python-2.6.1\PCbuild8\Win32
439 446 \endcode
440 447
441 448 To build all, do the following (after setting the above variables):
442 449
443 450 \code
444 451 > cd PythonQtRoot
445 452 > vcvars32
446 453 > qmake
447 454 > nmake
448 455 \endcode
449 456
450 457 This should build everything. If Python can not be linked or include files can not be found,
451 458 you probably need to tweak \b build/python.prf
452 459
453 460 The tests and examples are located in PythonQt/lib.
454 461
455 462 \subsection Linux
456 463
457 464 On Linux, you need to install a Python-dev package.
458 465 If Python can not be linked or include files can not be found,
459 466 you probably need to tweak \b build/python.prf
460 467
461 468 To build PythonQt, just do a:
462 469
463 470 \code
464 471 > cd PythonQtRoot
465 472 > qmake
466 473 > make all
467 474 \endcode
468 475
469 476 The tests and examples are located in PythonQt/lib.
470 477 You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime
471 478 linker can find the *.so files.
472 479
473 480 \subsection MacOsX
474 481
475 482 On Mac, Python is installed as a Framework, so you should not need to install it.
476 483 To build PythonQt, just do a:
477 484
478 485 \code
479 486 > cd PythonQtRoot
480 487 > qmake
481 488 > make all
482 489 \endcode
483 490
484 491 \section Tests
485 492
486 493 There is a unit test that tests most features of PythonQt, see the \b tests subdirectory for details.
487 494
488 495 \page Examples Examples
489 496
490 497 Examples are available in the \b examples directory. The PyScriptingConsole implements a simple
491 498 interactive scripting console that shows how to script a simple application. The PyLauncher application can be used to run arbitrary PythonQt scripts given on the commandline.
492 499
493 500 The following shows a simple example on how to integrate PythonQt into your Qt application:
494 501
495 502 \code
496 503 #include "PythonQt.h"
497 504 #include <QApplication>
498 505 ...
499 506
500 507 int main( int argc, char **argv )
501 508 {
502 509
503 510 QApplication qapp(argc, argv);
504 511
505 512 // init PythonQt and Python itself
506 513 PythonQt::init();
507 514
508 515 // get a smart pointer to the __main__ module of the Python interpreter
509 516 PythonQtObjectPtr context = PythonQt::self()->getMainModule();
510 517
511 518 // add a QObject as variable of name "example" to the namespace of the __main__ module
512 519 PyExampleObject example;
513 520 context.addObject("example", &example);
514 521
515 522 // do something
516 523 context.evalScript("print example");
517 524 context.evalScript("def multiply(a,b):\n return a*b;\n");
518 525 QVariantList args;
519 526 args << 42 << 47;
520 527 QVariant result = context.call("multiply", args);
521 528 ...
522 529 \endcode
523 530
524 531
525 532 */
General Comments 0
You need to be logged in to leave comments. Login now