1
0
mirror of https://github.com/thp/pyotherside.git synced 2025-01-28 23:52:55 +08:00
pyotherside/qpython_test.cpp
Thomas Perl 3836fdbc3d Cleaner variant: QVariant <-> PyObject * conversion
This new approach uses conversion of Python objects to
Qt objects and vice versa, and introduces some new API
such as "call(func, args)" and "addImportPath(path)".
2013-05-17 12:51:24 +02:00

40 lines
668 B
C++

#include "qpython_test.h"
#include "qpython.h"
#include <QDebug>
void
qpython_test()
{
QPython py;
py.addImportPath(".");
py.importModule("pyotherside");
qDebug() << py.evaluate("pyotherside.demo()");
QList<QVariant> l;
l << 1;
l << "Hello World";
l << 3;
QVariantList l2;
l2 << 4 << QString::fromUtf8("Jössas!") << 6;
l << QVariant(l2);
QMap<QString,QVariant> m;
m["Hello"] = 4711;
l << QVariant(m);
qDebug() << l;
QVariant v(l);
PyObject *o = py.toPython(v);
PyObject_Print(o, stdout, 0);
printf("\n");
QVariant l3 = py.fromPython(o);
qDebug() << l3;
Py_DECREF(o);
}