Shyamnath Premnadh
Shyamnath Premnadh aka Shyam
Qt for Python
Senior Software Engineer @ TQtc
... and many more
Python to the rescue 🐍
One can argue, those numbers are not really representative.
# Python
print("Python goes b" + "r"*10)
// C++
#include <iostream>
#include <string>
int main()
{
std::cout << "C++ goes b" << std::string(10,"r");
}
# Python
name = ["hello", "world"]
is_hello = True if "hello" in name else False
// C++
auto name = {"hello", "world"}
bool is_hello;
if (std::find_if(name.begin(), name.end(), "hello"))
is_hello = True;
else
is_hello = False;
# Python
# join a list of strings
words = ["this", "is", "a", "sentence"]
sentence = ' '.join(words)
//C++
auto words = {"This", "is", "a", "sentence"};
auto sentence = std::accumulate(words.begin(), words.end(), std::string{});
What else has a C++ backend ? 💭
The official set of Python bindings for the Qt framework.
...but not only that 🤔.
Qt for Python is also an application suite
More videos: https://doc.qt.io/qtforpython/videos.html
Let's look at some code 🤖
// Simple Engine
QScryptEngine e;
e.execute(...);
QVariant r = e.evaluate(...);
// Load Python module
QScryptModule mod(...);
// Get Function Reference
QScryptFunction f(..., &mod;);
// Call Function
QVariantList args;
QVariant r = f.call(args);
// [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
e.execute("print([i**3 for i in range(10)])");
// QVariant(QString, "Hello This Is A Test")
qDebug() << e.evaluate("f'hello this is a test'.title()");
//QVariant(double, 4950)
qDebug() << e.evaluate("sum(i for i in range(100))")
QScryptModule mod("super"); // super.py
QScryptFunction f1("add_three_numbers", &mod);
QVariantList args1;
args1 << 5 << 6 << 9;
// QVariant(double, 20)
qDebug() << f1.call(args1);
...I hear Kde likes Flatpak 🧐
Android Deployment:We are working on it
More platforms at wiki.qt.io/Qt_for_Python#Community
Shyamnath Premnadh
Kde Akademy 2022 | October 2, 2022