embeddedpyqt / doc / integration.rst

How to add EmbeddedPyQt to your C++ project

Six simple steps to embed Python into your Qt C++ project.

  1. Add the embpyqt folder to your project.
  2. Add the embpyqt-files and Python to your build. For qmake do
INCLUDEPATH += -I./embpyqt
    embpyqt/embeddedpyqt.cpp \
    embpyqt/embeddedpyqt.h \
# Python
LIBS        += -lpython2.7 -L/usr/lib/
INCLUDEPATH += /usr/include/python2.7/
  1. Create an EmbeddedPyQt instance in your project:
#include "embpyqt/embeddedpyqt.h"
EmbeddedPyQt embpyqt = new EmbeddedPyQt();
  1. Register classes and instances to embpyqt:

The instances will be known by their object name. To register classes you have to pass the staticMetaObject attribute.

If an instance is a child object of a already registered instance (like embpyqt) you do not have to register it manually. It will be accessible as an attribute. The same applies to instance properties.

  1. Call the init script:

Make sure that the python folder is copied to your installation target by your build system and that the path is correct.

  1. Now you can call Python from C++ by using the execute method:
embpyqt->execute("embpyqt_console.Visible = True", true);

Python can connect to existing C++ signals and is able to modify the user interface.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.