Add qtjambi.jar to the classpath of your Java project containing the most essential Qt Core, Gui and Widgets modules. If you use Maven to build your application simply add following dependency to your project:
<dependency>
<groupId>io.qtjambi</groupId>
<artifactId>qtjambi</artifactId>
<version>$VERSION</version>
</dependency>(exchange $VERSION either by 5.15.11, 6.2.9 or by 6.4.1).
Otherwise, download QtJambi JAR file from Maven Central Repository. Find the list of all available QtJambi modules.
Create a file Test.java containing the following code
import io.qt.widgets.*;
public class Test {
public static void main(String[] args) {
QApplication.initialize(args);
QMessageBox.information(null, "QtJambi", "Hello World!");
QApplication.shutdown();
}
}Compile the file:
javac -cp qtjambi-6.4.1.jar Test.javaFor execution you need the platform dependent binaries of QtJambi. For
instance, if you are working on Windows download the windows-x64
binaries. Additionally, you need Qt. Use the Qt
installer to install Qt on
your system. Make sure you are using the same Qt version and QtJambi
version (e.g. 5.15 or 6.3). On Linux, you can alternatively use Qt system libraries (correct version provided).
The required DLLs are to be found in the bin folder on Windows and lib folder on Linux and macOS, respectively.
When running a QtJambi application you have to make the locations of Qt and QtJambi libraries known to Java. Therefore, use the PATH environment (LD_LIBRARY_PATH on Linux, DYLD_FRAMEWORK_PATH on macOS) or the Java runtime property java.library.path.
The example program can be executed this way on Windows:
java -cp qtjambi-6.4.1.jar;qtjambi-native-windows-x64-6.4.1.jar;. -Djava.library.path=C:\Qt\6.4.0\msvc2019_64\bin TestOn Linux it looks this way:
java -cp qtjambi-6.4.1.jar:qtjambi-native-linux-x64-6.4.1.jar:. -Djava.library.path=<path to>/Qt/6.4.0/gcc_64/lib TestOn macOS you additionally need to use the start parameter -XstartOnFirstThread:
java -cp qtjambi-6.4.1.jar:qtjambi-native-macos-6.4.1.jar:. -Djava.library.path=<path to>/Qt/6.4.0/macos/lib -XstartOnFirstThread TestQtJambi automatically detects the required native component jars if they are located next to their Java counterparts.
You can simply skip qtjambi-native-OS-VERSION.jar in your classpath (-cp). Nevertheless, qtjambi-native-OS-VERSION.jar bundles are
extracted every time at program startup. By default, this is a process specific temporal directory purged after program shutdown.
Alternatively, you can use Java system property io.qt.deploymentdir to let libraries to be exctacted and persist in user
application data path or common directory (see below).
In general, you can start learning how to use Qt in Java as it is introduced for C++. There are a couple of specifics for QtJambi that are introduced here. Instead of starting your program with a java command as shown above you can deploy your application as executable as described here. Read here about creating self-exctracting bundles containing Qt library. Read more about developing applications for Android.
See QtJambi 5.15 API Reference Documentation, QtJambi 6.2 API Reference Documentation and QtJambi 6.4 API Reference Documentation
Following system properties are accepted by QtJambi.
You can specify Java system properties as start argument -Dproperty=value or in Java code System.setProperty("property", "value").
io.qt.log-messages- By specifying any combination ofALL,CRITICAL,DEBUG,WARNING,FATAL,INFOandSYSTEMyou can install a message handler causing exceptions to be thrown in the event of a message of given type.io.qt.exceptions-for-messages- By specifying any combination ofALL,CRITICAL,DEBUG,WARNING,FATAL,INFOandSYSTEMyou can install a message handler forwarding messages of given types to Java logging.
io.qt.library-path-override- Use this property if you want to force Java to load Qt and QtJambi libraries from other paths than given byjava.library.path.io.qt.debug- Specifydebugto force Java using debug libraries of Qt and QtJambi.io.qt.verbose-loading- Specifytrueto cause QtJambi to print out library loading steps.io.qt.pluginpath- Specify list of paths added as plugin search path.
If you native library bundles QtJambi extracts these components to temporary directory each time at program startup. Typically, it is a process specific directory purged at program termination.
io.qt.keep-temp-deployment- Specifytrueto avoid library deletion at program termination. The libraries remain in temporary directory instead.io.qt.deploymentdir- Specifyuserto let QtJambi extract libraries to user's application data directory. Specifycommonto let them be extracted to common program data directory. Specify a target directory to let them be extracted there.io.qt.no-deployment-spec- Specifytrueif you want to inhibit the search for native library bundles at all and load QtJambi from library path instead.
io.qt.allow-nonfinal-signals- Specifytrueto avoid exception to be thrown when detecting non-final signal declarations.io.qt.no-library-shutdown-hook- Specifytrueto avoid library shutdown at program termination.io.qt.disable-thread-affinity-check- Specifytrueto avoid thread affinity checks when accessingQObjects. Use this property to improve performance in release versions of your well tested applications.io.qt.disable-event-thread-affinity-check- ...the same applying to access checks during event handling.io.qt.no-app-deletion- Specifytrueif you combine native code with Java code and yourQCoreApplicationinstance has been created elsewhere than inside Java.
io.qt.enabled-qml-debugging- Specifytrueto allow QML debugging for the entire runtime of the application.io.qt.enabled-qml-debugging-nowarn- ...also inhibits a security warning.
Along with this use program argument -qmljsdebugger=... to enable QML debugging for Qt.