Timo
Timo

Reputation: 1814

How to provide Scripting support for Qt-Applications?

I'm looking for a scripting language which can be integrated into my Qt5 Application. The application has a public api, which can be used to extend the application with plugins. Now I want to add a scripting language to the application which provides access to the whole public api. The scripting language must fulfill the following Requirements:

I evaluated the following Script-Languages:

What scripting-languages and tools do you suggest, that fulfills all my requirements?

Upvotes: 8

Views: 2237

Answers (1)

Timo
Timo

Reputation: 1814

SWIG with Python seems to be a good choice. SWIG is still actively maintained.

Although SWIG doesn't fulfill all of my requirements out of the box, it shouldn't be that a big thing to make all of them work:

Script Code can be executed from within the QT-Application.

This is not supported out of the box. You have to embed a python interpreter into your application. https://docs.python.org/2/extending/embedding.html

The user can access the file-system, network and create graphical elements from the scripting language.

Accessing the filesystem and network should not be a problem with python. To create graphical userinterfaces, there are a lot of libraries available:
https://wiki.python.org/moin/GuiProgramming

  • The user can access the public api of my QT Application through bindings.
  • There should be a generator available to automatically generate script-language bindings for my public api.

This is done by SWIG. They provide great C++ and c++11 support.

For classes that are part of the Public Api, it should be possible to pass around objects between the QT-Application and the Scripting Engine.

This is possible using the c++ functions provided by swig:

  • SWIG_TypeQuery gets you information about C++ types
  • SWIG_NewPointerObj converts a c++ object to a python (proxy) object
  • SWIG_ConvertPtr converts a python (proxy) object back to c++ object

More info in the External runtime chapter

Upvotes: 2

Related Questions