GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing mevislab.github.io — PythonQt: Examples

PythonQt
Examples

Examples are available in the examples directory. The PyScriptingConsole implements a simple 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.

The following shows a simple example on how to integrate PythonQt into your Qt application:

#include "PythonQt.h"
#include <QApplication>
...
int main(int argc, char *argv[])
{
QApplication qapp(argc, argv);
// init PythonQt and Python itself
PythonQt::init();
// get a smart pointer to the __main__ module of the Python interpreter
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
// add a QObject as variable of name "example" to the namespace of the __main__ module
PyExampleObject example;
context.addObject("example", &example);
// do something
context.evalScript("print example");
context.evalScript("def multiply(a,b):\n return a*b;\n");
QVariantList args;
args << 42 << 47;
QVariant result = context.call("multiply", args);
...
PythonQt.h
PythonQtObjectPtr
a smart pointer that stores a PyObject pointer and that handles reference counting automatically
Definition PythonQtObjectPtr.h:57
PythonQtObjectPtr::evalScript
QVariant evalScript(const QString &script, int start=Py_file_input)
evaluates the given script code in the context of this object and returns the result value
PythonQtObjectPtr::addObject
void addObject(const QString &name, QObject *object)
add the given object to the module as a variable with name (it can be removed via clearVariable)
PythonQtObjectPtr::call
QVariant call(const QString &callable, const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap())
call the given python object (in the scope of the current object), returns the result converted to a ...
PythonQt::init
static void init(int flags=IgnoreSiteModule|RedirectStdOut, const QByteArray &pythonQtModuleName=QByteArray())
PythonQt::getMainModule
PythonQtObjectPtr getMainModule()
get the main module of python
PythonQt::self
static PythonQt * self()
get the singleton instance

Generated on for PythonQt by doxygen 1.15.0
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.