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

samuel ammonius sfammonius at gmail.com
Sat Sep 10 20:13:53 CEST 2022


> First, your own example of not having compile-time checking of the means
that
> those programmers are accepting less security for the sake of staying in
the
> same language.

How? It's just the equivalent of static_cast(), and I'm talking about types
with
the same sizes. If the types were of different sizes, the cast would cause a
warning.

> Second and most importantly, they don't need to switch the entire code
base.
> They need only to add some C++ source files to their software so they can
use
> Qt from there. Their existing logic can remain in C as much as they'd
like. It
> stands to reason no one is using Qt from C today because there is no
binding,
> so we're not asking for porting. All such potential codebases would need
new
> code added anyway, so why not add the new code in C++?

Firstly, because this makes the code much more complicated to read, write,
and
compile. Secondly, Imagine if Qt was written in Rust or Java, and you were
writing
a program in C++. It is possible to mix the two languages, but it would
mean the
difference of learning a new API to learning a new programming language. I
know
that C++ is much more similar to C than it is to Java or Rust, but it would
still suck
even if you already knew those languages, because you wanted to use C++.

I've written programs in the way you're describing, where the main()
function and
the Qt code is in C++ and the logic is in C. It is not fun to have to
create a function
for every time you switch between the two since you can't mix them in one
file.
You have to do something like using "extern int bla" to share variables and
convert to-and-from QString and char* every time you want to pass the data
along.
There's also the overhead of functions, and the only way to avoid it is for
the
developer to bind Qt to C themselves in the way I've been describing.

> The issue here is *automation*. A human can look at the parameters and
decide
> that this function should be called "parent" and this other one "text",
but
> how does a tool do that in an automated fashion?

The automation can just use the type:

void QPushButton3_int_bool_charP(int a, bool b, char *c);
void QPushButton3_bool_charP_intP(bool a, char *b, int *c);

It doesn't really matter what the functions are called since the user is
only calling them through a macro. The automation tool could even just
decide to call them QPushButton3_74358724 and QPushButton3_12347934
as long as it makes sure that the macro redirects to them when the right
parameters are used.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220910/2944735d/attachment.htm>


More information about the Development mailing list