lyoneel / qtjambi

QtJambi is a wrapper for using Qt in Java.

Home Page:http://www.qtjambi.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QtJambi - Java Bindings for Qt

QtJambi - Java Bindings for Qt

Overview

QtJambi is Qt bindings for the Java programming language originally developed by Trolltech, the predecessor of The Qt Company. The successive open source project provides bindings of Qt5 and Qt6 releases for latest Java JDK versions.

The bindings are generated by inspection of the C++ header files of the Qt implementation then emitting code to provide the necessary JNI (Java Native Interface) and .java files to provide linkage to Java. An application programmer using QtJambi would simply add the coresponding Java libraries (.jar files) to their Java project to be able to develop and deploy their application.

Availability

Maven Central

QtJambi is available for Java 8 or 11 and higher using Qt5.15 and Qt6 in Java on Windows, Android Linux and macOS. Most Qt modules are available as QtJambi module as listed here. All modules are published as Maven Artifact.

Support

QtJambi is an open source project making the power of Qt available for your Java projects free of charge. However, this project is causing ongoing costs. Please consider supporting this project by donation. Your support is highly appreciated.

Donate with PayPal

How To Build From Sources

If you just want to use QtJambi for your application development you can skip these instructions and simply use the provided binaries from the list of modules. Make yourself familiar with developing applications with QtJambi.

Requirements

  • Apache Ant (min. 1.10.x)
  • Java Development Kit (e.g. OpenJDK, tested with Java 1.8 and 18)
  • Qt 5.15 or 6.x (using the Qt Online Installer)
  • C++ compiler (Gcc, Clang, MSVC2019)
  • chrpath (Linux only)
  • XCode command line tools (macOS only)

Building QtJambi

If you do'nt need the entire set of Qt modules available in Java edit property qtjambi.skipped.modules in build.properties and exclude Qt modules you don't need. This saves compilation time.

Pre-Build Steps On Windows

  • Open the Visual Studio command prompt for x64 architecture.

to be found in: --> Start Menu --> Programs --> Visual Studio 2019 --> Visual Studio Tools --> VC

  • Change to directory of your QtJambi clone

  • Set paths:

> set JAVA_HOME_TARGET=path to your java jdk

> set PATH=...\apache-ant-1.10.3\bin;%PATH%

> set QTDIR=C:\Qt\6.4.1\msvc2019_64

Pre-Build Steps On Linux and macOS

  • Open a shell and change to directory of your QtJambi clone

  • Set paths:

> export JAVA_HOME_TARGET=path to your java jdk

> export QTDIR=/opt/Qt/6.4.1/gcc_64 on Linux

> export QTDIR=/opt/Qt/6.4.1/macos on macOS

Building Bindings

  • build QtJambi:

> ant all

(This step may take several hours.)

  • optionally, create and run unit tests:

> ant tests.generate tests.run

  • Find unit test results in directory TestResults.

  • Finally, find all Java libraries in directory $VERSION/deployment and all native libraries in platform- and configuration-specific subdirectory, e.g. native/windows-x64/release.

How To Use QtJambi

Example

Add qtjambi-VERSION.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.12, 6.2.10 or by 6.4.2).

Otherwise, download QtJambi JAR file from Maven Central Repository.

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.2.jar Test.java

Execute Example

For execution you need the platform dependent binaries of QtJambi either as self-extracting bundle or as library file (e.b. dll). For instance, if you are working on Windows download qtjambi-native-windows-x64-VERSION.jar from Maven Central Repository and add it to java class path. 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.x).

When running a QtJambi application you have to make the locations of Qt libraries known to Java. Therefore, use the PATH environment (LD_LIBRARY_PATH on Linux, DYLD_LIBRARY_PATH on macOS) or the Java runtime property java.library.path. By default, on Windows Qt libraries are located in bin directory and on Linux and macOS in lib directory. In case your Linux distribution provides Qt (of correct version) as system library you don't need to specify library path.

The example program can be executed this way on Windows:

java -cp qtjambi-6.4.2.jar;. -Djava.library.path=C:\Qt\6.4.1\msvc2019_64\bin Test

On Linux it looks this way:

java -cp qtjambi-6.4.2.jar:. -Djava.library.path=<path to>/Qt/6.4.1/gcc_64/lib Test

On macOS you additionally need to use the start parameter -XstartOnFirstThread:

java -cp qtjambi-6.4.2.jar:. -Djava.library.path=<path to>/Qt/6.4.1/macos/lib -XstartOnFirstThread 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.

Licenses

            GNU LESSER GENERAL PUBLIC LICENSE

 QtJambi is Copyright (C) 1992-2009 Nokia. All rights reserved.
            Copyright (C) 2009-2022 Dr. Peter Droste, 
                                    Omix Visualization GmbH & Co. KG. 
                                    All rights reserved.

 You may use, distribute and copy QtJambi under the terms of
 [GNU Lesser General Public License version 2.1](LICENSE.LGPLv21).
            GNU GENERAL PUBLIC LICENSE

 QtJambi is Copyright (C) 1992-2009 Nokia. All rights reserved.
            Copyright (C) 2009-2022 Dr. Peter Droste, 
                                    Omix Visualization GmbH & Co. KG. 
                                    All rights reserved.

 You may use, distribute and copy QtJambi under the terms of
 GNU Lesser General Public License version 3. That license references
 the [General Public License version 3](LICENSE.GPLv3). Other
 portions of the QtJambi may be licensed directly under this license.

Further Reading

About

QtJambi is a wrapper for using Qt in Java.

http://www.qtjambi.io

License:Other


Languages

Language:C++ 47.2%Language:Java 36.6%Language:QML 15.4%Language:C 0.6%Language:QMake 0.2%Language:Objective-C++ 0.0%Language:HTML 0.0%Language:Batchfile 0.0%