[Development] How to make a qt6 module using cmake?

Alexandru Croitor alexandru.croitor at qt.io
Tue Nov 21 15:47:51 CET 2023



> On 21. Nov 2023, at 13:21, Bogdan Vatra via Development <development at qt-project.org> wrote:
> 
> Hello there,

Hi,

> 
>  I'm trying to port a qt5 module to qt6 which it seems starting with 6.4.x 
> the qmake support is broke/removed for modules so I'm forced to use cmake...
> 
> I checked other qt modules (e.g. https://code.qt.io/cgit/qt/qtmqtt.git/tree) 
> and I did mostly the same but there are a few problems:
> 
> - They all use *internal* (version specific) stuff (e.g. 
> qt_internal_project_setup, qt_internal_add_qml_module, etc.).

There is no public api for building regular qt modules, so you need to use qt_internal_add_module and friends.

> - the `install` target doesn't install examples srcs.

That's a recent feature that comes with qt 6.6
See the commit message for the relevant configure args
https://codereview.qt-project.org/c/qt/qtbase/+/494874

> - how to add docs to examples? With qmake I needed only to have a `doc` 
> folder in the example folder and it will parse all the .qdoc files for me.

I don't think we have a "standalone" docs feature just for an example.
Instead you need to configure docs for the module, and then should also generate docs for examples.

Following the template of qtsvg is probably a good way to do it.

Make sure to adapt paths in the .qdocconf file to your own file structure.

https://github.com/qt/qtsvg/blob/dev/src/svg/doc/qtsvg.qdocconf
https://github.com/qt/qtsvg/blob/dev/doc/src/examples/delayedencoding.qdoc
https://github.com/qt/qtsvg/blob/dev/src/svg/CMakeLists.txt#L63


> - the `docs` target doesn't seem to work:
> ```
> qt.qdoc: Cannot find index directory:  "/home/bogdan/work/qt/qtmqtt/b/./doc"
> /home/bogdan/work/qt/qtmqtt/src/mqtt/doc/qtmqtt.qdocconf:1: (qdoc) error: 
> Cannot open file '//./doc/global/qt-module-defaults.qdocconf': No such file or 
> directory
> Cannot open file '//./doc/global/qt-module-defaults.qdocconf': No such file or 
> directory
> ```

Looking at those paths, it's as if the install prefix is missing. But i'm not sure if you're trying to configure qtmqtt or your own repo with semi-adapted qtmqtt-inspired changes.


> So, what's the recommended way to make a qt6 module using cmake?

To follow the template of any other of the qt repos. qtsvg is small enough. qtmqtt as well.



More information about the Development mailing list