KDChart3.0 compilation process-compiled using QT5.15 and QT6.x

Article directory

  • Reference original text
    • 1. Download the KDChart source file
    • 2. Download and install CMake
    • 3. Compile
      • Qt5.15.0 compilation
      • Qt6.x compilation
        • Compiled with Qt6.X, this is the fastest.
    • 4. Use
      • Test method one:
      • Test method two:

Refer to the original text

Record my KDChart3.0 compilation process
System: win11, Qt5.15, compiler mingw 64-bit

Copyright statement: This article is an original article by the blogger and follows CC 4.0
BY-SA
Copyright agreement, please attach the original source link and this statement when reprinting.

Note that KDChart3.0 requires QT5.15 and above.

  • This article is compiled using Qt6.4.3. It is recommended to read and record my KDChart3.0 compilation process when using QT5.15.
  • If you can’t read it, this article is also compiled with QT5.15.

1. Download the KDChart source file

Open the official website https://www.kdab.com/development-resources/qt-tools/kd-chart/

Pull it to the bottom,


image-20231023225936339

  • Download the source file and unzip it.

  • Check INSTALL.txt in the folder and you can see that CMake compilation is required.

image-20231023230311958

Chinese Version

These are instructions for installing KD Chart using the CMake build system.
Requires CMake version 3.3 or higher.

Qt version supports:

KD Chart 2.5.0 or below requires Qt4
KD Chart 2.5.1 to 2.7.2 requires Qt4 to Qt5.15
KD Chart 2.8.x removed Qt4 support (i.e. Qt5 only)
KD Chart 3.0 or higher requires Qt5.15.0 to Qt6.x (if you need to support older versions of Qt5, please send an email to [email protected])
Note that Qt6 builds require a C++17 compliant compiler, while Qt5 builds pass the C++11 standard.

See the comments at the top of CMakeLists.txt for the available configuration options that can be passed to cmake.

The installation directory on Windows defaults to c:\KDAB\KDChart-<version>,
The default for non-Windows platforms is /usr/local/KDAB/KDChart-<version>.
You can change this location by passing option -DCMAKE_INSTALL_PREFIX=/install/path to cmake.

1) Create a build directory from the top directory of your KD Chart installation:

mkdir build

and switch to that build directory:

cd build

2) Now run one of 'cmake' depending on the desired build type:
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DKDChart_STATIC=True -DCMAKE_BUILD_TYPE=Debug ..
cmake -DKDChart_STATIC=True -DCMAKE_BUILD_TYPE=Release ..

To define a location for installation, use the following command:
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=C:/kdchart ..
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/opt/kdchart ..

3) Unix
Set LD_LIBRARY_PATH to point to the lib directory of the KD Chart installation. If you haven't set LD_LIBRARY_PATH yet, run in the terminal:
% LD_LIBRARY_PATH=/path/to/kdchart/lib:$LD_LIBRARY_PATH
% export LD_LIBRARY_PATH

The above must be added to your .bashrc or similar file to persist. Of course, you can also run it from the shell before building the software that uses KD Reports,
But in this case your settings are only available in this shell.

4) MacOS
Follow the description above, but use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH

5) Windows
For running the executable, add the KD Chart dll (kdchart\bin) path to PATH. For example: set PATH=\path\to\kdchart\bin;%PATH%
For development, add the KD Chart lib (kdchart\lib) path to the LIB environment variable. For example: set LIB=\path\to\kdchart\lib;%LIB%

6) Build everything by typing:

From your top-level KD Chart directory run:

% make # Unix, Mac
% nmake # Windows

7) (Optional:) Install KD Chart:

From your top-level KD Reports directory run:

% make install # Unix, Mac
% nmake install # Windows

This will copy the necessary files into a subdirectory of the installation path:
For Unix/Linux, Mac: /usr/local/KDAB/KDChart-VERSION/
For Windows this is: C:\KDAB\KDChart-VERSION\

8) Check out the sample applications that will help you get started with KD Chart.

==Test==
To build the test kit, pass -DKDChart_TESTS=true to CMake as follows:
% cmake -DKDChart_TESTS=true

Then run 'make test' to run the unit tests.

==Use==
From your CMake project add

find_package(KDChart CONFIG REQUIRED)

or in case of Qt6

find_package(KDChart-qt6 CONFIG REQUIRED)

and linked to the imported target KDChart::kdchart.
That's all you need to do (imported targets also come with include directories).

Depending on where you installed KDChart, you may also need to specify the CMAKE_PREFIX_PATH environment variable.

2. Download and install CMake

Notice:

If you use Qt6.x compilation, you don’t need to install it. Qt6 comes with CMake, so you don’t need to configure it! (Look directly at 3. Compilation -> Qt6.x Compilation)

CMake download https://cmake.org/download/

image-20231023232107794

I chose the installation version based on my system.

Basically the default settings are used during installation. Desktop icons can be checked.

3. Compilation

We first create two folders to store cmake compiled files.

I put the folder under the kdchart source file.

image-20231023232622610

Then open the cmake you just installed.

Fill in the source file directory and build folder directory.

image-20231023233549034

Click Configure.

Select the compiler and specify the local directory.


image-20231023233854222

To select the compiler address in the Qt installation directory.

image-20231023234614407

Click Finish and it says the file cannot be found.


image-20231023234835956

Qt5.15.0 compilation

The message box prompts that these two files cannot be found. This file is located in the installation directory. Pay attention to the compiler version in the address.

Fill in the address into the Qt5_DIR item in the CMake software.

image-20231023235832084

Then click Configure. Still getting an error, this time Qt5sql is missing.

Fill in the address,

Click Configure again. This time the window is no longer red and no error is reported.

Qt6.x compilation

image-20231024001904430

  • Qt6Config.cmake qt6-config.cmake not found, fill in Qt6_DIR, then click Configure

image-20231024002309753

  • Qt6CoreToolsConfig.cmake qt6coretools-config.cmake not found; fill in Qt6GuiTools_DIR, then click Configure

image-20231024002657653

CMake: Allow setting Qt6_DIR to find packages when not cross-compiling

image-20231024004247925

Solution:

1. Setting Qt6_close is not enough to find Qt packages

2.c++ CMake cannot find package in Qt6 installation

There is also an article on how to use it:

set up

QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH

QT_ADDITIONAL_PACKAGES_PREFIX_PATH

image-20231024014211452

but i didn’t succeed

If compiled using Qt6.X, this is the fastest
  • Directly use the cmake-gui that comes with QT6 (QT\6.x\Tools\CMake_64\bin\cmake-gui)

    image-20231024214855128

Click Configure first, without reporting an error, click Generate.

image-20231024014731703

Select the desired build version (debug or release). I chose release this time (the debug version has been compiled).

Scroll down, this is the install folder, you can change it to a location you like, but remember it.

After making changes, click Generate.

It worked.

Open the CMD window as administrator and cd to the build folder just now.

image-20231024215425486
image-20231024215647943

Switch to a non-C drive, such as F drive:

C:\> F:
F:\> cd xxx

Enter the command mingw32-make.exe

This must be mingw32, don’t fill in 64 just because it is a 64-bit compiler.

Press Enter. Compilation takes a long time, please wait a while.

After completion, enter mingw32-make.exe install

image-20231024014915908

Once completed, go to the install folder.

This compiles it.

The main thing is to use these files.

Compiled with Qt5.15.0

“C:\Program Files (x86)\KDChart\bin\libkdchart3.dll”

“C:\Program Files (x86)\KDChart\lib\libkdchart3.dll.a”

“C:\Program Files (x86)\KDChart\include\KDChart”

Compiled with Qt6.x

“C:/Program Files (x86)/KDChart/lib/libkdchart-qt63.dll.a”
“C:/Program Files (x86)/KDChart/bin/libkdchart-qt63.dll”

“C:/Program Files (x86)/KDChart/include/KDChart”

4. Use

Save the compiled header files and library files to the project directory.

The debug library files are (libkdchart3d.dll, libkdchart3d.dll.a)/(I did not compile debug)

The release library files are (libkdchart3.dll, libkdchart3.dll.a)/(libkdchart-qt63.dll, libkdchart-qt63.dll.a)

Let’s create a new Qt project and run it.

Test method one:

Put the corresponding version of the file in the project directory.

Then add these header files and libraries to the .pro file.

Copy an example from the official document. https://docs.kdab.com/kdchart/latest/

#include "mainwindow.h"
#include <QApplication>
#include <KDChartWidget>

int main(int argc, char *argv[]){<!-- -->
    QApplication a(argc, argv); // Create application object

    MainWindow w;//Create the main window object
    w.show(); // Display the main window

    KDChart::Widget widget; // Create KDChart widget object
    widget.resize( 600, 600 ); // Set the widget size

    QVector< qreal > vec0, vec1, vec2; // Create containers for three data sets
    vec0 << -5 << -4 << -3 << -2 << -1 << 0 << 1 << 2 << 3 << 4 << 5; // Add data points to vec0
    vec1 << 25 << 16 << 9 << 4 << 1 << 0 << 1 << 4 << 9 << 16 << 25; // Add data points to vec1
    vec2 << -125 << -64 << -27 << -8 << -1 << 0 << 1 << 8 << 27 << 64 << 125; // Add data points to vec2

    widget.setDataset( 0, vec0, "Linear" ); // Associate vec0 with the label "Linear" and add it to the widget
    widget.setDataset( 1, vec1, "Quadratic" ); // Associate vec1 with the label "Quadratic" and add it to the widget
    widget.setDataset( 2, vec2, "Cubic" ); // Associate vec2 with the label "Cubic" and add it to the widget

    widget.show(); // Display the graph widget

    return a.exec(); // Start the application's event loop
}

run.

Test method two:

  • Use Qt Creator to open the official example of downloaded KDChart source code KDChart-kdchart-3.0\tests\Gantt\apireview

    image-20231024232748587

Open CMakeLists.txt in Qt Creator and add the following:

##
# This file is part of the KD Chart library.
#
# SPDX-FileCopyrightText: 2019-2023 Klar?lvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: MIT
#
#Specify that the minimum required CMake version is 3.5
cmake_minimum_required(VERSION 3.5)

#Define the project name as 18qt6-cmake, specify the project version as 0.1, and the programming language used as C++.
project(Ganttapireview-manual-test VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON) #Enable automatic UI compilation
set(CMAKE_AUTOMOC ON) #Enable automatic MOC (Meta-Object Compiler)
set(CMAKE_AUTORCC ON) #Enable automatic RCC (Resource Compiler)

set(CMAKE_CXX_STANDARD 11) #Set the C++ standard to C++11

#Requires use of specified C++ standard
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#Specify the path of the dynamic library to be linked
link_directories("C:/Program Files (x86)/KDChart/lib/")


#Find the Qt library and specify the required components as Widgets. It automatically finds and sets Qt variables based on the available Qt version
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets PrintSupport)

#Find and set the required Qt Widgets component based on the main Qt version number
find_package(Qt${<!-- -->QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets PrintSupport)

#Define project source file list
set(PROJECT_SOURCES
    entrydelegate.cpp
    entrydialog.cpp
    entrydialog.ui
    main.cpp
    mainwindow.cpp
    mainwindow.ui
)

#If the Qt major version is greater than or equal to 6, use qt_add_executable to create the target
if(${<!-- -->QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Ganttapireview-manual-test
        MANUAL_FINALIZATION
        ${<!-- -->PROJECT_SOURCES}
    )
# Otherwise, use add_library or add_executable to create the target depending on the platform and Qt version.
else()
    #android
    if(ANDROID)
        add_library(Ganttapireview-manual-test SHARED
            ${<!-- -->PROJECT_SOURCES}
        )
# Define Android properties after find_package() call in Qt 5:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(Ganttapireview-manual-test
            ${<!-- -->PROJECT_SOURCES}
        )
    endif()
endif()

#Link the Qt Widgets library to the target
target_link_libraries(Ganttapireview-manual-test
    PRIVATE Qt${<!-- -->QT_VERSION_MAJOR}::Widgets
    Qt${<!-- -->QT_VERSION_MAJOR}::PrintSupport
    # Generated library name
    kdchart-qt63
    #kdchart
    #testtools
)

#Add the include path of the header file of the dynamic library to be linked to the target file
target_include_directories(Ganttapireview-manual-test
    PRIVATE "C:/Program Files (x86)/KDChart/include/KDChart-qt6")

#Set target properties, such as MacOSX Bundle identifier, version, etc.
set_target_properties(Ganttapireview-manual-test PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${<!-- -->PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${<!-- -->PROJECT_VERSION_MAJOR}.${<!-- -->PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

#Install target files
install(TARGETS Ganttapireview-manual-test
    BUNDLE DESTINATION.
    LIBRARY DESTINATION ${<!-- -->CMAKE_INSTALL_LIBDIR})

#If the main Qt version is 6, use qt_finalize_executable to complete the final setting of the target
if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(Ganttapireview-manual-test)
endif()

Build, select Release/Debug to run (based on the generated library)

  • Gantt chart

image-20231024232332368