views:

59

answers:

2

I'm writing a Qt based (QtCore) C++ library and would like to have access to it from Java and Python. Python is not a problem because of PySide and SIP. But I can't seem to find any information about doing the same with Java. The fact that Java bindings exist for Qt makes me hopefuly that there is a way to create bindings for a custom Qt based library.

Has anyone done this? Or have any information or pointers on how this can be done?

A: 

http://www.swig.org/ has a program called swig. This program allows you to generate bindings , which create functions in languages like Java or Python that simply call the appropriate C(++) function For example if you have a C++ function int add(int x, int y), running the prototype/definition through SWIG would create a Java wrapper that would call that function. Any libraries the C code uses are irrelevant.

krzysz00
The problem with SWIG is that it doesn't understand the particulars of Qt. SIP and PySide for example generate bindings that work well with Qt. I have used SWIG with C++ (that didn't depend on Qt) and while it works the generated wrapper code is huge, especially if you start using STL templates.The answer I'm looking for is more with respect to possibly using the same generator as used by Qt Jambi. But I can't find any information on this.
lex
A: 

Qt Jambi included a generator that you could use on your own Qt classes.

However, Nokia discontinued support for Jambi after v4.5.

For technical details, see http://doc.qt.nokia.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-generator.html .

Also, there's an early white paper still at http://www.sra.co.jp/qt/relation/qtjambi-whitepaper-tp3.pdf with details of the generator in chapter 4.

Andy Thomas-Cramer