Restricting access to C++ classes from JavaScript

There are cases when you want to provide a rich interface for a class to manipulate it from within C++ easily, but to have strict control over what can be done using scripting, you want to prevent scripters from using some of the properties or methods of the class.

The safest approach is to create a wrapper class that only exposes the allowed methods and signals. This will allow you to design your original classes freely. For example, if you want to hide some methods, it's quite easy—just don't make them slots and don't declare them with Q_INVOKABLE. However, you may want them to be slots in the internal implementation. By creating a wrapper class, you can easily hide slots of the internal ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.