O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing C++ objects from QML

Let's say that we want to perform a heavy calculation in C++ and access it from our QML calculator. We will choose factorial for this project.

The QML engine is really fast, so you can most likely calculate factorials directly in JavaScript without performance problems. We just use it here as a simple example.

Our goal is to inject our C++ class into the QML engine as a JavaScript object that will be available in our QML files. We will do that exactly like we did it in Chapter 10, Scripting. The main function creates a QQmlApplicationEngine object that inherits QJSEngine, so we have access to the API that is already familiar to us from that chapter. Here, we'll just show how we can apply this knowledge to our ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required