Using Qt with Alternative Programming Languages

Using Qt with Alternative Programming Languages - Part 2

By Jeff Tranter

In Part 1 of this series we looked at some of the programming languages other than C++ that could be used with the Qt framework. Let's continue our discussion, looking at some more languages.

OCaml

Caml is a dialect of the ML programming language family. OCaml, originally known as Objective Caml, extends the Caml language with object-oriented constructs.

Lablqt 1 is a project that aims to support using QML with back end code written in OCaml rather than C++. It supports Qt 5. At the moment, it appears to be more of a proof of concept suited to small applications, and will require more development work before it is complete.

PHP

PHP is a server-side scripting language designed for web development that can also be used as a general-purpose programming language.

PHP-Qt 2 is an extension for PHP version 5 that provides an object-oriented interface to the Qt 4 framework. It appears the code is no longer maintained, as the last release was in 2007.

Pascal

Pascal is a procedural programming language designed by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming. A derivative known as Object Pascal, designed for object-oriented programming, was developed in 1985.

Free Pascal is an open source compiler for Pascal and Object Pascal that supports a large number of processor architectures and operating systems.

Qt for Pascal 3 is a set of bindings to allow Free Pascal to interface with Qt version 4. The binding does not cover the whole Qt framework, only the classes needed by the cross platform Lazarus IDE to use Qt as a widget set. There is an alpha release available, which supports Qt 5.

Perl

Perl is a general-purpose, interpreted, scripting language originally developed by Larry Wall. Perl versions 5 and 6 are considered distinct languages and continue to be developed independently.

The KDE project has developed a set of Perl bindings for Qt 4 called Perl Qt 4. It also provides an integrated development environment (IDE) called Project Manager that supports using forms created with Qt Designer and generating Perl Qt code from the forms.

Python

Python is a widely used general-purpose, high-level, interpreted programming language.

PyQt 5,  a set of Python version 2 and 3 bindings for Qt 4 and 5, runs on all platforms supported by Qt. It is developed by Riverbank Computing. PyQt is dual licensed under the GNU GPL v3 and a commercial license. Unlike Qt, PyQt is not available under the LGPL, so use with proprietary applications generally requires using the commercial version of PyQt.

PySide 6 is another Python binding for Qt. It is released under the LGPL, and was originally developed by Nokia after they failed to reach an agreement with Riverbank Computing to change its licensing terms to include the LGPL as an alternative license. The PySide Qt bindings allow both free/open source and proprietary software development and is maintained by the Open Source community.

In my experience, Python is the most widely used alternative language for Qt. Both PyQt and PySide are actively maintained and have a complete development toolchain including support for Qt Designer user interface (UI) files. They expose the entire Qt API to Python using the same class and method names as in C++. A short example is below, which should be familiar to users of Qt from C++. Note that is can be run directly by the Python interpreter.

#!/usr/bin/python
 
# Import PySide classes
import sys
from PySide.QtCore import *
from PySide.QtGui import *
 
# Create a Qt application
app = QApplication(sys.argv)

# Create a Label and show it
label = QLabel("Hello World")
label.show()

# Enter Qt application main loop
app.exec_()
sys.exit()

R

R is a programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians and data miners for developing statistical software and data analysis.

There was a project 7 to create a collection of R packages to provide an interface to the Qt framework. The focus was on enabling GUI development and advanced graphics. It supports Qt 4.6 or later. The project has been inactive since about 2009.

Ruby

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language designed and developed by Yukihiro Matsumoto.

Qt for Ruby 8 is a set of bindings to both the KDE and Qt APIs. The Korundum package includes both a QtRuby Qt-only binding along with the full combined Qt/KDE one. The QtRuby package contains just Qt bindings with no dependencies on KDE. It supports Qt version 4.

Ruby-qml 9 is a Qt Quick/QML wrapper for Ruby that provides bindings between QML and Ruby and allows you to use Qt Quick-based GUIs from Ruby. It supports Qt 5.4 or later.

Rust

Rust is a general-purpose, multi-paradigm, compiled programming language developed by Mozilla Research.

Qmlrs 10 allows the use of Qt Quick/QML code from Rust. Specifically, it allows Rust code to create a Qt Quick engine and load a QML script, and for QML code to invoke Rust functions.

Scheme

Scheme is another dialect of the Lisp programming language. CHICKEN is a compiler for Scheme that produces portable C code and runs on desktop platforms.

Qt for CHICKEN Scheme 11 is a set of bindings for Qt version 4, supporting the GUI classes as well as networking and D-Bus. It was last updated in 2010.

Tcl

Tcl, or Tool Command Language, is a scripting language created by John Ousterhout. It is a small, lightweight language interpreter intended to be embedded into applications. It optionally provides a GUI toolkit called Tk.

Qt/KDE-Tcl 12 allows using Qt as a GUI framework from Tcl. The most recent release was made in 2012 and supports Qt 4.8.

Summary

In this two-part blog post I've covered most of the alternative Qt languages that I was able to find, although I skipped a few of the more obscure ones like Harbour and Julia.

It is interesting to note that some of these alternative languages chose to support QML. This suggests that there is significant interest in QML itself and validates the approach that Qt has been promoting to focus on QML for defining GUIs, rather than the traditional C++ and widgets solution.

Looking to the future, an interesting language is Apple's Swift 13. Apple has been promoting it as the successor to Objective-C and the preferred language for developing on its iOS, OS X, and watchOS platforms. While previously a proprietary product, Apple is currently transitioning it to Open Source, and plans to support more platforms, including Linux. This may make it a much more attractive programming language, and supporting bindings to Qt would make for an interesting project. 

References

  1. Using OCaml and Qt Together, lablqt project web page, http://kakadu.github.io/lablqt
  2. PHP-Qt project, web page, http://sourceforge.net/projects/php-qt
  3. Free Pascal Qt 4 Binding, project wiki page, http://wiki.lazarus.freepascal.org/Qt4_binding
  4. Perl Bindings for the Qt Libraries, web page, https://projects.kde.org/projects/kde/kdebindings/perl/perlqt
  5. What is PyQt?, web page, http://www.riverbankcomputing.com/software/pyqt/intro
  6. An Introduction to PySide, wiki page, http://wiki.qt.io/PySide
  7. Interfaces to the Qt framework from R, web page, http://qtinterfaces.r-forge.r-project.org
  8. Korundum/QtRuby - Ruby-KDE/Qt bindings, web page, http://techbase.kde.org/Development/Languages/Ruby
  9. QML/Qt Quick bindings for Ruby, web page, http://seanchas116.github.io/ruby-qml
  10. Qt Quick interface for Rust, web page, http://github.com/cyndis/qmlrs
  11. Qt 4 Egg, web page, http://wiki.call-cc.org/eggref/4/qt
  12. QTcl Project, web page http://sourceforge.net/projects/qtcl
  13. Swift Overview, Apple Developer web-site, http://developer.apple.com/swift/