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.8
, 6.2.6
or by 6.3.3
).
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.3.3.jar Test.java
For execution you need the platform dependent binaries of QtJambi. For
instance, if you are working on Windows download and unpack the win64
binaries. The required DLLs are to be found in the bin
folder (lib
folder on Linux and macOS). 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).
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:
java -cp qtjambi-6.3.3.jar;qtjambi-native-windows-x64-6.3.3.jar;. -Djava.library.path=C:\Qt\6.2.0\msvc2019_64\bin Test
On macOS you need to use the start parameter -XstartOnFirstThread
:
java -XstartOnFirstThread -cp qtjambi-6.3.3.jar:qtjambi-native-windows-x64-6.3.3.jar:. -Djava.library.path=C:\Qt\6.2.0\msvc2019_64\bin Test
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.3 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
,INFO
andSYSTEM
you 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
,INFO
andSYSTEM
you 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
- Specifydebug
to force Java using debug libraries of Qt and QtJambi.io.qt.verbose-loading
- Specifytrue
to 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
- Specifytrue
to avoid library deletion at program termination. The libraries remain in temporary directory instead.io.qt.deploymentdir
- Specifyuser
to let QtJambi extract libraries to user's application data directory. Specifycommon
to let them be extracted to common program data directory. Specify a target directory to let them be extracted there.io.qt.no-deployment-spec
- Specifytrue
if you want to inhibit the search for native library bundles at all and load QtJambi from library path instead.
io.qt.allow-nonfinal-signals
- Specifytrue
to avoid exception to be thrown when detecting non-final signal declarations.io.qt.no-library-shutdown-hook
- Specifytrue
to avoid library shutdown at program termination.io.qt.disable-thread-affinity-check
- Specifytrue
to avoid thread affinity checks when accessingQObject
s. 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
- Specifytrue
if you combine native code with Java code and yourQCoreApplication
instance has been created elsewhere than inside Java.
io.qt.enabled-qml-debugging
- Specifytrue
to 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.