[Development] Could support for C be added to Qt?

Karl Semich 0xloem at gmail.com
Sat Sep 10 16:05:46 CEST 2022


> its apps and users. Many of these programs are built on top of years of C
> code,
> so I don't think it would be easy for the developers of those programs to
> switch
> from C to C++ even if they wanted to.

Allan’s proposal to keep the code C but ensure it builds with a C++
compiler likely had precisely this kind of scenario in mind. It does
help others to make a generic interface. It is likely a lot more work.
Experience with an AI-assisted IDE could speed things.

> <https://github.com/sammonius/qtc>

nice

> Qt was when I started that project, so I was going to try starting from
> scratch by making a script that generates bindings from Qt's header files,
> but I wanted to see if having it built-into Qt was an option first.

> The problem is that C++ doesn't let you get the address of
> constructors/destructors.
> The only option might be to make a function that calls "new" and returns
> it, and same
> with delete, but that would probably destroy the point of having the
> bindings internal
> so I don't know what to do.

Yes, I imagine constructors basically need a wrapper function that
calls new or placement new, or a template. If the bindings were
internal, the constructor could be statically linked and possibly
inlined into the wrapper. Of course, you would only call a C++ member
function from C++ code as they have different calling conventions from
C functions, so that can mean a lot of wrappers.

Qt has such a strong C++ basis that I personally might take the small
performance hit of keeping C bindings more separate, to make merging
forward easier.


More information about the Development mailing list