Home · Examples 


Functions and Enums

So far, we have simply let the generator map functions automatically. However, we can also exclude functions, add new functions, and modify functions with the generator, by for instance changing parameter types, removing parameters, and altering the return type.

The generator knows how to modify some functions by itself. Notably, it can convert between the Qt and Java collection classes - such as QList and java.util.List. In some cases, the generator needs help to be able to port specific functions.

Instead of implementing an exmaple, we will select function modifications from the Qt library type systems. This will allow us to see some real life type system implementation issues. We will examine the modifications on a case by case basis.

You could also check out the Generator Example, which also has examples of function modifications.

Returning references to value types

In a few cases in the Qt API, we find functions that return a reference to a value type. We will take QPoint's rx() as an example. This function returns a reference to the int holding the x-coordinate of the point.

This will result in a QNativePointer being returned from the function. It is not possible for Jambi to convert this into an int (or Integer for that matter); the int primitive cannot point to a C++ value.

In this case, the function will have to be removed.

Non-virtual functions with native pointer arguments

The usual way to handle functions with native pointer arguments is to change the functions access to private. You then create a wrapper Java function, which calls the function you have made private. This new function takes more friendly parameters, and does type conversions before calling the private function.

C++ operators

Java does not support overloading operators. The generator automatically crates a function for the operator called "opetator_%operatorname%", where operatorname is the C++ name of the operator. It might be a good idea to change the name to be more Java friendly. You do that by making the operator function private and creating a wrapper function to call the private one.

We take the * operator of QPoint as an example:

Virtual functions with native pointers.

If you have a virtual function that needs to be altered, you get a problem in that a new java function will not override the orignial C++ function in the shell class.

To remedy this, you can insert code into the C++ shell class, which does parameter conversion inside the


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Jambi 4.5.2_01