{"id":26070014,"url":"https://github.com/rcalixte/libqt6c","last_synced_at":"2025-04-11T18:50:57.179Z","repository":{"id":281245111,"uuid":"944500360","full_name":"rcalixte/libqt6c","owner":"rcalixte","description":"Qt 6 for C","archived":false,"fork":false,"pushed_at":"2025-03-30T20:42:16.000Z","size":6533,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T21:21:27.486Z","etag":null,"topics":["bindings","c","gui-library","qt","qt6","zig-package"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcalixte.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-07T13:05:39.000Z","updated_at":"2025-03-24T01:49:02.000Z","dependencies_parsed_at":"2025-03-30T21:30:57.341Z","dependency_job_id":null,"html_url":"https://github.com/rcalixte/libqt6c","commit_stats":null,"previous_names":["rcalixte/libqt6c"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcalixte%2Flibqt6c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcalixte%2Flibqt6c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcalixte%2Flibqt6c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcalixte%2Flibqt6c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcalixte","download_url":"https://codeload.github.com/rcalixte/libqt6c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248464142,"owners_count":21108229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bindings","c","gui-library","qt","qt6","zig-package"],"created_at":"2025-03-08T23:06:59.982Z","updated_at":"2025-04-11T18:50:57.166Z","avatar_url":"https://github.com/rcalixte.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg alt=\"libqt6c\" src=\"assets/libqt6c.png\" height=\"128px;\" /\u003e\n\n![MIT License](https://img.shields.io/badge/License-MIT-green)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rcalixte/libqt6c)](https://goreportcard.com/report/github.com/rcalixte/libqt6c)\n[![Static Badge](https://img.shields.io/badge/v0.14%20(stable)-f7a41d?logo=zig\u0026logoColor=f7a41d\u0026label=Zig)](https://ziglang.org/download/)\n\u003c/div\u003e\n\n---\n\nMIT-licensed Qt 6 bindings for C\n\nThis library is a straightforward binding of the Qt 6.4+ API. You must have a working Qt 6 C++ development toolchain to use this binding. The [Building](#building) section below has instructions for installing the required dependencies.\n\nThis library is designed to be used as a dependency in a larger application and not as a standalone library. The versioning scheme used by this library is based on the Qt version used to generate the bindings with an additional nod to the library revision number. Any breaking changes to the library will be reflected in the changelog.\n\nThese bindings are based on the [MIQT bindings for Go](https://github.com/mappu/miqt) that were released in 2024. The bindings are complete for QtCore, QtGui, QtWidgets, QtCharts, QtMultimedia, QtMultimediaWidgets, QtNetwork, QtPrintSupport, QtSpatialAudio, QtSvg, QtWebChannel, QtWebEngine, QScintilla, and others. There is support for slots/signals, subclassing, custom widgets, async via Qt, etc., but the bindings may be immature or unstable in some ways. It is fairly easy to encounter segmentation faults with improper handling. Q3 of the [FAQ](#faq) is a decent entry point for newcomers. Please try out the library and start a [discussion](https://github.com/rcalixte/libqt6c/discussions) if you have any questions or issues relevant to this library.\n\n---\n\nTABLE OF CONTENTS\n-----------------\n\n- [Supported Platforms](#supported-platforms)\n- [License](#license)\n- [Examples](#examples)\n- [Building](#building)\n- [Usage](#usage)\n- [FAQ](#faq)\n- [Special Thanks](#special-thanks)\n\nSupported platforms\n-------------------\n\n| OS      | Arch   | Linkage (Bindings) | Status  |\n| ------- | ------ | ------------------ | ------- |\n| FreeBSD | x86_64 | Static             | ✅ Works |\n| Linux   | arm64  | Static             | ✅ Works |\n| Linux   | x86_64 | Static             | ✅ Works |\n\nLicense\n-------\n\nThe `libqt6c` bindings are licensed under the MIT license.\n\nYou must also meet your Qt license obligations.\n\nExamples\n--------\n\nThe [`helloworld`](https://github.com/rcalixte/libqt6c-examples/tree/master/src/helloworld/main.c) example follows:\n\n```c\n#include \u003clibqt6c.h\u003e\n#include \u003cstdint.h\u003e\n#include \u003cstdio.h\u003e\n\n#define BUFFER_SIZE 64\n\nstatic long counter = 0;\n\nvoid button_callback(void* self) {\n    counter++;\n    char buffer[BUFFER_SIZE];\n    snprintf(buffer, BUFFER_SIZE, \"You have clicked the button %ld time(s)\", counter);\n    q_pushbutton_set_text(self, buffer);\n}\n\nint main(int argc, char* argv[]) {\n    // Initialize Qt application\n    q_application_new(\u0026argc, argv);\n\n    QWidget* widget = q_widget_new2();\n    if (!widget) {\n        // we can use assert or check for null to simulate exception handling\n        // assert(widget != NULL);\n        fprintf(stderr, \"Failed to create widget\\n\");\n        return 1;\n    }\n\n    // We don't need to free the button, it's a child of the widget\n    QPushButton* button = q_pushbutton_new5(\"Hello world!\", widget);\n    if (!button) {\n        fprintf(stderr, \"Failed to create button\\n\");\n        return 1;\n    }\n\n    q_pushbutton_set_fixed_width(button, 320);\n    q_pushbutton_on_clicked(button, button_callback);\n    q_widget_show(widget);\n\n    int result = q_application_exec();\n    q_widget_delete(widget);\n\n    printf(\"OK!\\n\");\n\n    return result;\n}\n```\n\nFull examples are available in the [`libqt6c-examples`](https://github.com/rcalixte/libqt6c-examples) repository.\n\nBuilding\n--------\n\nFreeBSD (native)\n----------------\n\n- *Tested with FreeBSD 14 / Qt 6.8 / GCC 13*\n\nFor dynamic linking with the Qt 6 system libraries:\n\n```bash\nsudo pkg install qt6-base qt6-charts qt6-multimedia qt6-svg qt6-webchannel qt6-webengine qscintilla2-qt6 zig\n```\n\n\u003e [!NOTE]\n\u003e The `zig` package may need to be downloaded or compiled and installed separately if the latest stable version is not available in the default repositories.\n\nLinux (native)\n--------------\n\n- *Tested with Debian 12 + 13 / Qt 6.4 + 6.8 / GCC 12 + 14*\n\n- *Tested with Linux Mint 22 / Qt 6.4 / GCC 13*\n\n- *Tested with Ubuntu 24.04 / Qt 6.4 / GCC 13*\n\n- *Tested with Fedora 41 / Qt 6.8 / GCC 14*\n\n- *Tested with EndeavourOS Mercury / Qt 6.8 / GCC 14*\n\nFor dynamic linking with the Qt 6 system libraries:\n\n- __Debian-based distributions__:\n\n```bash\nsudo apt install qt6-base-dev libqscintilla2-qt6-dev qt6-base-private-dev qt6-charts-dev qt6-multimedia-dev qt6-svg-dev qt6-webchannel-dev qt6-webengine-dev\n```\n\n\u003e [!NOTE]\n\u003e The `zig` package must be downloaded and installed separately.\n\n- __Fedora-based distributions__:\n\n```bash\nsudo dnf install qt6-qtbase-devel qscintilla-qt6-devel qt6-qtcharts-devel qt6-qtmultimedia-devel qt6-qtsvg-devel qt6-qtwebchannel-devel qt6-qtwebengine-devel zig\n```\n\n\u003e [!NOTE]\n\u003e The `zig` package will need to be downloaded and installed separately if the latest stable version is not available in the default repositories.\n\n- __Arch-based distributions__:\n\n```bash\nsudo pacman -S qt6-base qscintilla-qt6 qt6-charts qt6-multimedia qt6-svg qt6-webchannel qt6-webengine zig\n```\n\nOnce the required packages are installed, the library can be built from the root of the repository:\n\n```bash\nzig build\n```\n\nUsers of Arch-based distributions need to __make sure that all packages are up-to-date__ first and will need to add the following option to support successful compilation:\n\n```bash\nzig build -Denable-workaround=true\n```\n\nThe compiled libraries can be installed to the system in a non-default location by adding the `--prefix-lib-dir` option to the build command:\n\n```bash\nsudo zig build --prefix-lib-dir /usr/local/lib/libqt6c # creates /usr/local/lib/libqt6c/{libraries}\n```\n\nTo skip the restricted extras:\n\n```bash\nzig build -Dskip-restricted=true\n```\n\nTo see the full list of build options available:\n\n```bash\nzig build --help\n```\n\nUsage\n-----\n\n- If using Zig's build system, import the library into your project:\n\n```bash\nzig fetch --save git+https://github.com/rcalixte/libqt6c\n```\n\nAppend `#\u003ctag\u003e`, `#\u003ccommit\u003e`, or `#\u003cbranch\u003e` to the end of the URL to pin to a specific version of the library.\n\n- Add the library to your `build.zig` file:\n\n```zig\nconst qt6c = b.dependency(\"libqt6c\", .{\n    .target = target,\n    .optimize = .ReleaseFast,\n});\n\n// After defining the executable, add the include path from the library\nexe.root_module.addIncludePath(qt6c.path(\"include\"));\n\n// Link the compiled libqt6c libraries to the executable\n// qt_lib_name is the name of the target library without prefix and suffix, e.g. qapplication, qwidget, etc.\nexe.root_module.linkLibrary(qt6c.artifact(qt_lib_name));\n```\n\n__Extra options are required for building on Arch-based distributions. Refer to the build system at the examples link below for more details.__\n\n- Use the library in your code:\n\n```c\n// the main qt6 header to import (C ABI Qt typedefs are included)\n#include \u003clibqt6c.h\u003e\n```\n\nFull examples of the build system and sample applications can be found in the [`libqt6c-examples`](https://github.com/rcalixte/libqt6c-examples) repository. Cross-compilation is not supported by this library at this time.\n\nFAQ\n---\n\n### Q1. Can I release a proprietary, commercial app with this binding?\n\nYes. You must also meet your Qt license obligations: either dynamically link Qt library files under the LGPL or purchase a Qt commercial license for static linking.\n\n### Q2. How long does it take to compile?\n\nUnder normal conditions, the first compilation of the entire library should take less than 10 minutes, assuming the hardware in use is at or above the level of that of a consumer-grade mid-tier machine released in the past decade. Once the build cache is warmed up, subsequent compilations should be very fast, on the order of seconds. For client applications that use and configure a specific subset of the main library, the expected compilation time should be much shorter, e.g. compiling the `helloworld` example, only linking the libraries needed and without a warm cache, should take under 30 seconds. This assumes the Zig build system is being used.\n\n### Q3. How does the `libqt6c` API differ from the official Qt C++ API?\n\nSupported Qt C++ class methods are implemented 1:1 as C functions where the function names in C correspond to the snake_case equivalent of the combined Qt C++ class and method names, with the `Q` prefix altered to `q_`. [The official Qt documentation](https://doc.qt.io/qt-6/classes.html) should be used for reference and is included in the library wrapper header code (though not all links are guaranteed to work perfectly, nor is this functionality in scope for this project).\n\n- `QWidget::show()` is projected as `q_widget_show(void*)`\n- `QPushButton::setText(QString)` is projected as `q_pushbutton_set_text(void*, const char*)`\n\nAs a mental model, developers consuming this library should keep in mind that there are essentially two different tracks of memory management required for clean operation: one for the C++ side and one for the C side. The C side is managed by the developer and the C++ side has variant ownership semantics. Ownership semantics are documented throughout the [C++ documentation](https://doc.qt.io/qt-6/topics-core.html).\n\nThe library tries to adhere to idiomatic C where possible but is still bound by the complexity of the Qt C++ API. Knowledge of the Qt C++ API is required to understand and make full use of the library. While not an exhaustive list, there are some key topics to understand:\n\n- [Qt object ownership](https://doc.qt.io/qt-6/objecttrees.html)\n- [Qt signals and slots](https://doc.qt.io/qt-6/signalsandslots.html)\n- [Qt's property system](https://doc.qt.io/qt-6/properties.html)\n- [Qt's Meta-Object system](https://doc.qt.io/qt-6/metaobjects.html)\n- [Qt widgets](https://doc.qt.io/qt-6/examples-widgets.html)\n\nThe `QByteArray` and `QString` types are projected as plain C types available within the standard library: `char*` and `const char*`. The `QList\u003cT\u003e` and `QVector\u003cT\u003e` types are projected as `T**` or `T*[]` when used as an input parameter and supported by the helper library as `libqt_list\u003cT*\u003e` when used as a return type. The  `QMap\u003cK,V\u003e` and `QHash\u003cK,V\u003e` types are supported by the helper library as `libqt_map\u003cK,V\u003e` but are limited beyond basic capacities with no goal of feature expansion beyond the functionality required for adequate operation in the library. Consumers of this library are free to use types from other libraries as well, especially for hash types. The included helper library is not meant to be robust but merely to provide containers and functions for porting the Qt C++ API to a consumable C ABI. By default, this library does not expose the raw C ABI bindings and instead only makes the wrapper constructs available. Therefore, it is not possible call any of the Qt type's methods or the raw C ABI and some C equivalent method must be used instead. This library was constructed with the goal of enabling single-language application development. Anything beyond that boundary is up to the developer to implement.\n\n- C string types are internally converted to `QString` using `QString::fromUtf8`. Therefore, the C string input must be UTF-8 to avoid [mojibake](https://en.wikipedia.org/wiki/Mojibake). If the C input string contains binary data, the conversion would corrupt such bytes into U+FFFD (�). On return to C space, this becomes `\\xEF\\xBF\\xBD`.\n\n- The `libqt6c` library does not extend the C standard library and therefore it is up to the developer to provide their own functions for complex types like `QMap` and `QHash` beyond the scope of the helper library's containers.\n\nWhere Qt returns a C++ object by value (e.g. `QSize`), the binding may have moved it to the heap, and in C, this may be represented as a pointer type. In such cases, the caller is the owner and must free the object (using either `_delete` methods for the type or deallocation with `free`, `libqt_string_free`, etc.). This means code using `libqt6c` can look similar to the Qt C++ equivalent code but with the addition of proper memory management.\n\nThe `connect(targetObject, targetSlot)` methods are projected as `_on_(targetObject, void (*)())`. While the parameters in the methods themselves are more convenient to use, the documentation comments in the C header code should be used for reference for the proper usage of the parameter types and Qt vtable references. The example code above includes a simple callback function that can be used as a reference.\n\n- You can also override virtual methods like `paint_event` in the same way. Where supported, there are additional `_on_` and `_qbase_` variants:\n  - `on_paint_event`: Set an override callback function to be called when `paint_event` is invoked. For certain methods, even with the override set, the base class implementation can still be called by Qt internally and these calls can not be prevented.\n  - `qbase_paint_event`: Invoke the base class implementation of `paint_event`. This is useful for when the custom implementation requires the base class implementation. (When there is no override set, the `qbase_paint_event` implementation is equivalent to `paint_event`.)\n\nQt class inherited types are projected via void pointers and type casting in C. For example, to pass a `QLabel* myLabel` to a function taking only the `QWidget*` base class, it should be sufficient to pass `myLabel` and the library will automatically cast it to the correct type and Qt vtable reference.\n\n- When a Qt subclass adds a method overload (e.g. `QMenu::sizeHint(QMenu*)` vs `QWidget::sizeHint(QWidget*)`), the base class version is shadowed and can only be called via `q_widget_size_hint(void*)` while the subclass implementation can be called directly, e.g. `q_menu_size_hint(void*)`. Inherited methods are shadowed for convenience as well, e.g. `q_menu_show(void*)` is equivalent to `q_widget_show(void*)`. While the library aims to simplify usage, consideration should still be given to the Qt documentation for the proper usage of the parameter types and Qt vtable references.\n\nQt expects fixed OS threads to be used for each QObject. When you first call `q_application_new`, that will be considered the [Qt main thread](https://doc.qt.io/qt-6/thread-basics.html#gui-thread-and-worker-thread).\n\n- When accessing Qt objects from inside another thread, it's safest to use `q_threading_async` to access the Qt objects from Qt's main thread. The [Threading library](https://github.com/rcalixte/libqt6c/tree/master/src/threading/libqt6cthreading.c) documents additional available strategies within the header code.\n\nQt C++ enums are projected as PascalCase C typedef enums, replacing namespace indicators from C++ (`::`) with underscores and where enum values are represented by the uppercase equivalent of the Qt C++ class name, enum name, and enum value. For example, `Qt::AlignmentFlag` is projected as a C enum typedef of `Qt__AlignmentFlag` with values prefixed by `QT_ALIGNMENTFLAG`. Enums are not strongly typed in their definitions but are currently typed as `int64_t` parameters or return types by the C API.\n\nSome C++ idioms that were difficult to project were omitted from the binding. This can be improved in the future.\n\n### Q4. What build modes are supported by the library's build system?\n\nCurrently, only `ReleaseFast`, `ReleaseSafe`, and `ReleaseSmall` are supported. The `Debug` build mode is not supported. This may change in the future. The default build mode is `ReleaseFast`. To change the build mode:\n\n```bash\nzig build -Doptimize=ReleaseSafe\n```\n\n### Q5. Can I use another build system?\n\nIn theory, any build system that supports both C and C++ should work. However, this has only been lightly tested and is therefore unsupported and left as an exercise for the interested reader.\n\n### Q6. Can I use Qt Designer and the Qt Resource system?\n\nMIQT (the upstream Qt bindings for Go) has a custom implementation of Qt `uic` and `rcc` tools, to allow using [Qt Designer](https://doc.qt.io/qt-6/qtdesigner-manual.html) for form design and resource management. There is work in progress to support Qt Designer with this library in the future.\n\n### Q7. How can I add bindings for another Qt library?\n\nFork this repository and add your library to the `genbindings/config-libraries` file. [Read more »](cmd/genbindings/README.md)\n\nSpecial Thanks\n--------------\n\n- [@mappu](https://github.com/mappu) for the [MIQT](https://github.com/mappu/miqt) bindings that provided the phenomenal foundation for this project\n\n- [@arnetheduck](https://github.com/arnetheduck) for proving the value of collaboration on the back-end of this project while working across different target languages\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcalixte%2Flibqt6c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcalixte%2Flibqt6c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcalixte%2Flibqt6c/lists"}