aboutsummaryrefslogtreecommitdiffstats
path: root/examples/scriptableapplication
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scriptableapplication')
-rw-r--r--examples/scriptableapplication/CMakeLists.txt2
-rw-r--r--examples/scriptableapplication/mainwindow.cpp1
-rw-r--r--examples/scriptableapplication/pythonutils.cpp8
3 files changed, 10 insertions, 1 deletions
diff --git a/examples/scriptableapplication/CMakeLists.txt b/examples/scriptableapplication/CMakeLists.txt
index 999206425..5277d17d1 100644
--- a/examples/scriptableapplication/CMakeLists.txt
+++ b/examples/scriptableapplication/CMakeLists.txt
@@ -16,7 +16,7 @@ find_package(Qt5 5.12 REQUIRED COMPONENTS Core Gui Widgets)
# Use provided python interpreter if given.
if(NOT python_interpreter)
- find_program(python_interpreter "python")
+ find_program(python_interpreter NAMES python3 python)
endif()
message(STATUS "Using python interpreter: ${python_interpreter}")
diff --git a/examples/scriptableapplication/mainwindow.cpp b/examples/scriptableapplication/mainwindow.cpp
index 53aea3c71..4e4135fc6 100644
--- a/examples/scriptableapplication/mainwindow.cpp
+++ b/examples/scriptableapplication/mainwindow.cpp
@@ -67,6 +67,7 @@
#include <QtCore/QTextStream>
static const char defaultScript[] = R"(
+import AppLib
print("Hello, world")
mainWindow.testFunction1()
)";
diff --git a/examples/scriptableapplication/pythonutils.cpp b/examples/scriptableapplication/pythonutils.cpp
index c5e18f256..920d3e22e 100644
--- a/examples/scriptableapplication/pythonutils.cpp
+++ b/examples/scriptableapplication/pythonutils.cpp
@@ -68,8 +68,11 @@
extern "C" PyObject *PyInit_AppLib();
#else
extern "C" void initAppLib();
+# define PyInit_AppLib initAppLib
#endif
+static const char moduleName[] = "AppLib";
+
// This variable stores all Python types exported by this module.
extern PyTypeObject **SbkAppLibTypes;
@@ -113,6 +116,11 @@ State init()
if (qEnvironmentVariableIsSet(virtualEnvVar))
initVirtualEnvironment();
+ if (PyImport_AppendInittab(moduleName, PyInit_AppLib) == -1) {
+ qWarning("Failed to add the module '%s' to the table of built-in modules.", moduleName);
+ return state;
+ }
+
Py_Initialize();
qAddPostRoutine(cleanup);
state = PythonInitialized;