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?
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.
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.
Related
I have a source code library from Renesas for their Co2 sensor. The source code library is completely written in C language and a static library (with .a extension) of it is given for the Co2 sensor which was helpful for me to use it in any microcontroller that uses C/C++ language. Even there are a lot of examples of it.
So, I have a microcontroller called DPM5050 which runs in Java programming language. Therefore, I came to know, that it is possible to use the native code in JAVA using JNI (Java Native Interface). I also came to know that to use native source code in Java, I need a dynamic link library. But I only have a static library which is provided by the Renesas.
My question is how can I do that using a static library that was given by Renesas?
Can I able to change the static library to the dynamic link library by myself without contacting Renesas?
And how to implement this in Java using JNI to use the native source code library provided by the Renesas?
Since I just came to know about this JNI technology to use native
source code in Java. So, I would also like to ask you to give me
suggestions or opinions on this topic. And I am also looking for some
good documentation with examples or tutorials or guidance to proceed
further.
Right now, I am reading Java APIs, Extensions and Libraries: With JavaFX, JDBC, jmod, jlink, Networking, and the Process API - by Kishori Sharan's book in Chapter 7 of this book they have some details about JNI.
I am looking forward to your responses. Thanks in advance.
Kind Regards,
Mustaq.
How can I bind Qt with java by java java native interface?
I want to make an java app but for UI i want to use Qt, for some reason I can not use qt-jambi so I need to bind Qt with java.
Is it possible to create an Qt app in Qt creator and bind this component to java through java native interface?
If some one knows How qt-jambi works, please tell me, so help!
In fact my general question is that how (if its possible) to make a java app that some of its component like UI is written in c++? I do not want to use only one c++ method or library, I want to use I complete c++ qt app.
Thank you!
sorry for bad english.
When you want to have a hybrid Qt/Java application in which you use Qt API in Java code, definitely the best option is to use Qt Jambi. JNI only lets you to call some Java function from C++ world or vice-versa.
Qt Jambi enables you to to write software in Java in the speed of natively executable code and with native look and feel on different supported platforms. Actually it is a Java binding to Qt, so you can easily use Qt API in Java. There are some documentations on the web about it like this or that.
This may be a bit of an odd question, but I would like to know if you can use Java inside c++14. I don't really care for GTK (I find it confusing and over complicated). Swing, however, is very easy to use, and you can get a working project very quickly. So I would like to know if you can use Java Swing inside c++, so I can use Swing as the foreground, as in what you see like graphics, and use c++ for the background, as in stuff you cant see, like calculations and objects and stuff. So if I can have c++ code tell Swing what to look like, or when to update, that would be very useful for the project I have in mind. Thanks in advance for any advice I may receive.
EDIT: Being able to use c++14 inside Java would be acceptable as well. Also, if anyone could get me example code also, this would be very helpful. Thanks!
You shouldn't run Java from C++, but rather C++ from Java. Oracle gives you a way to load native shared libraries, using JNI.
So you would create your view in Java, using Swing, then you would update your view by calling C++ functions that were pre-compiled and exported in a shared library.
That said, using JNI is quite tricky and the speed improvements of C++ might not be worth it; so you should consider using only Java (or only C++ and a library to create your GUI, such as Qt)
In which direction you go is a matter of taste (loading the JVM from a C++ program or loading DLLs from the JVM side).
Usually you go the way which is more logical, e.g. if you already have a C++ program you likely want to load the JVM from the C++ side. That would be your case. Especially if the Java you want to add is essentially "scripting" the C++ application.
If you already have a Java program and want to access a C++ DLL, you load the DLL from Java and write a simple JNI / native Java class.
In our times you would use tools like JNA for that (instead of JNI): https://github.com/java-native-access/jna
Or you can use SWIG to generate wrappers for your C++ classes: http://www.swig.org/
I need to do the internationalization of an existing Java project. I am already using Qt Linguist in a C++ project using Qt and I would like (and have) to keep the same process for my Java project, instead of using the java RessourceBundles.
The help of lupdate specifies that it is possible to use Java files as input, but I have no idea of how to do this. Is it even possible ? Or is this purpose dead with Qt Jambi ?
Thanks,
Roland
Since the Jambi project is discontinued, you will probably not be able to use a current version of Qt Linguist with any Java project. Most features rely heavily on C++ specific language features (e.g. signatures of the translation methods, macros), so without a specific Java port it looks pretty bleak.
TLDR: Most likely: no. You will have use something different for translation (or write in C++ :) ).
I'm wondering if a Java library can be called from a VB.net application.
(A Google search turns up lots of shady answers, but nothing definitive)
No, you can't. Unless you are willing to use some "J#" libraries (which is not nearly the same as Java) or IKVM which is a Java implementation that runs on top of .NET, but as their documentation says:
IKVM.OpenJDK.ClassLibrary.dll: compiled version of the Java class libraries derived from the OpenJDK class library with some parts filled in with code from GNU Classpath and IcedTea, plus some additional IKVM.NET specific code.
So it's not the real deal.
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
You can call Java from .NET if you wrap it in some form to make it accessable and the easiest way is typically to use a Runtime bridge like
http://www.jnbridge.com/
Other way is to wrap your API with java webservices.
check this also http://www.devx.com/interop/Article/19945
Nothing out of the box.
Most java/.net interop that I know uses web services.
If you can create COM components with Java, you can use tlbimp to create an interop assembly for using in VB.Net.
If can create standard DLLs that can be used from C++ with Java, you can write P/Invoke declarations and call them from VB.Net.
If you can create a web service with Java, you can generate proxy class from the WSDL and call it from VB.Net.
In any case, chances are the Java component will live in a separate process. I doubt you can load both the Java VM and the CLR in the same process.
If you have the source code and compile it using the J# compiler, then the answer is yes. If you want to call any pre-Java 2 (aka 1.2) libraries, then these are included pretty much verbatim with J#. More recent stuff is going to be tricky though (i.e., it's not there).
An example where this is used commercially are the yFiles graph layout algorithms from yWorks. These were originally just a Java library, but for the past few years they've been offering a .NET version, which is just the Java version compiled with Visual J#.
It's not without problems, and there are some limitations that you can't get around, but it can be done. So... unfortunately this answer looks pretty shady as well.
You could use JNI to instantiate a virtual machine and then use Java Classes. It will be some fun, though, because you would need to use C++ as a bridge between VB.Net and Java.
This article in java world has a quick tutorial on how to use Java from C++ and viceversa.
http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
If you have the source, Visual Studio will let you convert Java code into c#.