diff options
| author | Alexandru Croitor <alexandru.croitor@qt.io> | 2018-06-07 11:17:32 +0200 |
|---|---|---|
| committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2018-06-07 11:17:37 +0200 |
| commit | 60a3b6a16304af4b1d8896a06b8407fe49f80ed2 (patch) | |
| tree | 6dca986c5e439c7cb39b17643129dadb436d2fea /examples/scriptableapplication/pythonutils.cpp | |
| parent | 33943b54e9470dc8830e94270e6521524acb2954 (diff) | |
| parent | 823eea34b77ca16a545a75b55619a5ed4da38c0e (diff) | |
Merge branch '5.9' into 5.11
Change-Id: I2de0fe8456fca242c56ea28520126f9ebbf540d8
Diffstat (limited to 'examples/scriptableapplication/pythonutils.cpp')
| -rw-r--r-- | examples/scriptableapplication/pythonutils.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/examples/scriptableapplication/pythonutils.cpp b/examples/scriptableapplication/pythonutils.cpp index 2f7d2c2ad..f546a5a6c 100644 --- a/examples/scriptableapplication/pythonutils.cpp +++ b/examples/scriptableapplication/pythonutils.cpp @@ -54,6 +54,8 @@ #include <QtCore/QCoreApplication> #include <QtCore/QDebug> #include <QtCore/QStringList> +#include <QtCore/QTemporaryFile> +#include <QtCore/QDir> #include <sbkpython.h> #include <sbkconverter.h> @@ -122,7 +124,7 @@ bool bindAppObject(const QString &moduleName, const QString &name, return false; PyTypeObject *typeObject = SbkAppLibTypes[index]; - PyObject *po = Shiboken::Conversions::pointerToPython(reinterpret_cast<const SbkObjectType *>(typeObject), o); + PyObject *po = Shiboken::Conversions::pointerToPython(reinterpret_cast<SbkObjectType *>(typeObject), o); if (!po) { qWarning() << __FUNCTION__ << "Failed to create wrapper for" << o; return false; @@ -152,17 +154,22 @@ bool runScript(const QStringList &script) { if (init() == PythonUninitialized) return false; + + // Concatenating all the lines + QString content; + QTextStream ss(&content); + for (const QString &line: script) + ss << line << "\n"; + + // Executing the whole script as one line bool result = true; - for (const QString& lineS : script) { - const QByteArray line = lineS.toUtf8(); - if (PyRun_SimpleString(line.constData()) == -1) { - if (PyErr_Occurred()) - PyErr_Print(); - qWarning() << __FUNCTION__ << "Error at" << line; - result = false; - break; - } + const QByteArray line = content.toUtf8(); + if (PyRun_SimpleString(line.constData()) == -1) { + if (PyErr_Occurred()) + PyErr_Print(); + result = false; } + return result; } |
