Qt Base Documentation

repository·dev·Indexed 25 days ago

https://github.com/qt/qtbase

Core of the Qt framework providing fundamental libraries and tools for building cross-platform applications. Includes comprehensive guides on building Qt 6 using CMake and Ninja, developer build modes, and cross-compilation for Android and iOS. Documentation also covers the use of helper scripts like qt-cmake, qt-configure-module, and qt-cmake-create, as well as Coin build and test templates and standardized documentation templates for Qt application examples and tools.

Tokens
46K
Snippets
82
Records
283
Agent score
84%

What's inside qtbase

  1. Overview of HarfBuzz components

    dev

    HarfBuzz is a font platform and text shaping engine supporting OpenType and Apple Advanced Typography (AAT). It is organized into core, auxiliary, and experimental libraries:

    Core Libraries

    • libharfbuzz: Handles text shaping, drawing, and painting. Supports various integration backends like hb-ft (FreeType), hb-coretext (macOS), hb-uniscribe (Windows), hb-directwrite (Windows), hb-gdi (Windows), hb-glib, and hb-graphite2.
    • libharfbuzz-subset: Provides font subsetting and variable-font instancing.

    Auxiliary Libraries

    • libharfbuzz-icu: Provides ICU Unicode integration.
    • libharfbuzz-cairo: Provides Cairo rendering integration.
    • libharfbuzz-gobject: Provides GObject/GI bindings.

    Experimental Libraries

    • libharfbuzz-raster: Glyph rasterization to bitmaps (includes color fonts) using hb-draw and hb-paint.
    • libharfbuzz-vector: Glyph output to vector formats like SVG using hb-draw and hb-paint.
    • libharfbuzz-gpu: Encodes glyph outlines for GPU rasterization (Slug algorithm) and provides shader sources in GLSL, WGSL, MSL, and HLSL.
  2. Choose between TurboJPEG and libjpeg APIs

    dev

    libjpeg-turbo provides two distinct APIs for JPEG compression and decompression:

    • TurboJPEG API: A straightforward, easy-to-use interface for in-memory operations. It is recommended for first-time users and includes specialized functionality like generating planar YUV images or performing multiple simultaneous lossless transforms.
    • libjpeg API: The industry-standard API. It is more powerful but more complex to use. It is API/ABI and mathematically compatible with libjpeg v6b and can be configured for v7/v8 compatibility.

    There is no significant performance difference between the two APIs for similar operations.

  3. Understand internal Qt Wayland protocol extensions

    dev

    The protocol extensions located in src/3rdparty/wayland/extensions/ are considered internal implementation details of Qt. They are subject to removal, renaming, or changes without warning.

    Compatibility Guarantee: Since Qt 5.4, Qt guarantees backwards compatibility for these protocols via renaming. If a client detects a global from one of these extensions, it can safely bind to it; existing events and requests will maintain the same number of arguments regardless of the compositor version. This ensures compatibility in environments where multiple Qt versions coexist (e.g., a statically linked application running against a system-installed Qt compositor).

  4. Understand the PCRE2 License terms

    dev

    PCRE2 (releases 10.00 and above) is distributed under the BSD-3-Clause WITH PCRE2-exception license.

    Key Licensing Details:

    • Basic Library Functions: Distributed under the standard BSD license.
    • Just-In-Time (JIT) Compilation Support: This is an optional feature. When included, it is licensed under the 2-clause BSD license.
    • Documentation: Distributed under the same terms as the software.
    • Test Data: Located in the testdata directory; it is not copyrighted and is in the public domain.
    • SLJIT: Code in the deps/sljit directory has its own separate LICENSE file.

    Redistribution Requirements (BSD License):

    1. Source Code: Must retain all copyright notices, the list of conditions, and the disclaimer.
    2. Binary Form: Must reproduce the copyright notices, conditions, and disclaimer in the documentation and/or other materials provided with the distribution.
    3. Endorsement: The names of the University of Cambridge or any contributors may not be used to endorse products derived from this software without specific prior written permission.

    Exemption for Binary Library-Like Packages

    The requirement to reproduce copyright notices in binary form does not apply transitively down a software chain. If Package A includes PCRE2, Package A must comply. If Package B includes Package A, Package B is not required to comply with the PCRE2 notice requirement unless Package B uses PCRE2 independently.

  5. Generate a CycloneDX SBOM

    dev

    The Qt CycloneDX SBOM helper tool is designed to work with the Qt CMake build system. It is not intended for standalone use.

    Workflow:

    1. The Qt CMake build system generates an intermediate TOML file during the build process.
    2. The Python script processes this TOML file to produce the final CycloneDX SBOM in JSON format.
  6. Configure Coin build and test templates

    dev

    Coin uses YAML templates to manage build and test instructions for Qt and related modules.

    Build Templates

    • coin_qtbase_build_template_v2: Used for building qtbase. Supports cross-compilation for targets like Android, iOS, and qemu configurations.
    • coin_module_build_template_v2: The counterpart to the qtbase template, used for building other repositories.

    Test Templates

    • coin_module_test_template_v1: Legacy template with instructions embedded in module_config.yaml (no cross-compilation support).
    • coin_module_test_template_v2: Supports building tests for other repos and qemu cross-compiling configurations. It avoids running tests on cross-compiling configurations.
    • coin_module_test_template_v3: Enforces test success in CI by not ignoring exit codes during run test instructions.
  7. Use the 'if' command correctly

    dev

    To avoid common pitfalls with variable evaluation and falsy values in CMake:

    • Check for empty string: To check if a variable is exactly an empty string (and not just falsy), use STREQUAL "". If the variable might be undefined, wrap it in quotes: if("${var_name}" STREQUAL "").
    • Check for definedness: Use if(DEFINED var_name).
    • Check for non-falsy values: Use if(var_name). Falsy values include 0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, "", or a string ending in -NOTFOUND.
    • Avoid double evaluation: Never use if(${var_name}). This can lead to errors if the variable contains content that CMake tries to parse as a command.
    # Correct: Check if a variable is an empty string (safe for undefined variables)
    if("${var_name}" STREQUAL "")
        message("${var_name}")
    endif()
    
    # Correct: Check if a variable is defined
    if(DEFINED var_name)
    endif()
    
    # Correct: Check for non-falsy values (0, OFF, FALSE, etc.)
    if(var_name)
        message("${var_name}")
    endif()
    
    # WRONG: Leads to double evaluation problems
    if(${var_name})
        message("${var_name}")
    endif()
  8. Run the glgen application to generate OpenGL classes

    dev

    The glgen application generates OpenGL-related classes from the official Khronos OpenGL specification and typemap files.

    To run the application, you must manually download the following files and place them in the application directory:

    1. gl.spec from http://www.opengl.org/registry/api/gl.spec
    2. gl.tm from http://www.opengl.org/registry/api/gl.tm

    Note: These files are not included in the Qt Project's repository to avoid copyright issues and to ensure human control over the OpenGL version used.

  9. Emulate libjpeg v7 or v8 ABI

    dev

    By default, libjpeg-turbo is based on libjpeg v6b. To support applications built against libjpeg v7 or v8 without recompiling them, you can build libjpeg-turbo with ABI emulation using CMake flags.

    Build commands:

    • For v7 emulation: -DWITH_JPEG7=1
    • For v8 emulation: -DWITH_JPEG8=1
  10. Structure an application example documentation

    dev

    Follow this structure when documenting a Qt application example to ensure completeness:

    • Overview: State the objective, the Qt technologies used, and the specific Qt features demonstrated.
    • Workflow Diagram (Optional): For complex examples, include a workflow diagram.
    • Running the Example:
    • Platform Information (Optional): List any platform-specific limitations or exceptions.
    • UI Walkthrough (Optional): For complex UIs, describe how to navigate and access different parts of the application.
    • Qt Classes and Modules (Optional): List the main Qt classes and modules used.
      • Class Diagram (Optional): Visually depict the hierarchy of the Qt classes used.
    • Feature Descriptions: Create a section for each major feature (e.g., #### Describe Feature A) explaining its implementation in the code.
    • Squish Testing (Optional): If the example was tested with Squish, include squish-tested-example.qdocinc.
    • Best Practices (Optional): Add any relevant best practices.
    • Links: Use the \sa command to link to 'All Qt Examples' and other relevant documentation. Note that the \example command automatically generates a link to the source code.
  11. Build the Emoji Segmenter from source

    dev

    If you need to modify the grammar and regenerate the C source files, you must have ragel installed.

    Follow these steps:

    1. Install Ragel (e.g., via apt-get).
    2. Run make to regenerate emoji_presentation_scanner.c and emoji_presentation_scanner_vs.c.
    apt-get install ragel
    make
  12. Follow the Qt CMake Coding Style

    dev

    When contributing CMake scripts to the Qt project, follow these general conventions:

    • Local Context: When in doubt, prefer the existing local code conventions of the file or function you are editing.
    • Functions vs. Macros: Prefer functions over macros to avoid parameter escaping issues.
    • Macro Variables: Always prefix local variables within a macro to prevent naming collisions.
    • Indentation: Use 4 spaces for indentation.
    • Command Casing: Use lowercase for command names (e.g., add_executable()) and shouty case for command flags/options (e.g., file(GENERATE OUTPUT ...)).