466 PythonQtPassOwnershipToPython<QGraphicsItem*> createNewItemOwnedByPython();
469 void addItemToCPP(PythonQtPassOwnershipToPython<QGraphicsItem*> item);
472 void addItemToCPP(PythonQtPassOwnershipToPython<QList<QGraphicsItem*> > items);
475 void addItemParent(QGraphicsItem* wrappedObject, PythonQtNewOwnerOfThis<QGraphicsItem*> parent);
478 \page Building Building
480 PythonQt requires at least Qt 5.0 and Python 2.7.x or Python 3.6 (or higher).
481 To compile PythonQt, you will need a python developer installation which includes Python's header files and
482the python2x.[lib | dll | so | dynlib].
483 The recommended way to build PythonQt is to use the QMake-based *.pro file.
484 The build scripts are currently set to use Python 3.10 by default.
485 You may need to tweak the \b build/python.prf file to set the correct Python includes and libs on your system.
489 On Windows, the (non-source) Python Windows installer can be used.
490 Make sure that you use the same compiler as the one that your Python distribution is built with.
491 If you want to use another compiler, you will need to build
492 Python yourself, using your compiler.
494 To build PythonQt, you need to set the environment variable \b PYTHON_PATH to point to the root
495 dir of the python installation and \b PYTHON_VERSION should state the used Python version.
497 When using the prebuild Python installer, this will be:
500 > set PYTHON_PATH = c:\Python310
501 > set PYTHON_VERSION = 3.10
504 When using the python sources, this will be something like:
507 > set PYTHON_PATH = c:\yourDir\Python-3.10.12\
508 > set PYTHON_VERSION = 3.10
511 To build all, do the following (after setting the above variables):
520 This should build everything. If Python can not be linked or include files can not be found,
521 you probably need to tweak \b build/python.prf
523 The tests and examples are located in PythonQt/lib.
525 When using a Python distribution, the debug build typically does not work because the
526 pythonxx_d.lib/.dll are not provided. You can tweak linking of the debug build to the release
527 Python version, but this typically requires patching pyconfig.h and removing Py_DEBUG and linker pragmas
532 On Linux, you need to install a Python-dev package.
533 If Python can not be linked or include files can not be found,
534 you probably need to tweak \b build/python.prf
536 To build PythonQt, just do a:
544 The tests and examples are located in PythonQt/lib.
545 You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime
546 linker can find the *.so files.
550 On Mac, Python is installed as a Framework, so you should not need to install it.
551 To build PythonQt, just do a:
561 There is a unit test that tests most features of PythonQt, see the \b tests subdirectory for details.
563 \page Examples Examples
565 Examples are available in the \b examples directory. The PyScriptingConsole implements a simple
566 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.
568 The following shows a simple example on how to integrate PythonQt into your Qt application:
571 #include "PythonQt.h"
572 #include <QApplication>
575 int main(int argc, char *argv[])
578 QApplication qapp(argc, argv);
580 // init PythonQt and Python itself
583 // get a smart pointer to the __main__ module of the Python interpreter
584 PythonQtObjectPtr context = PythonQt::self()->getMainModule();
586 // add a QObject as variable of name "example" to the namespace of the __main__ module
587 PyExampleObject example;
588 context.addObject("example", &example);
591 context.evalScript("print example");
592 context.evalScript("def multiply(a,b):\n return a*b;\n");
595 QVariant result = context.call("multiply", args);