<div dir="ltr">Hello,<div><br></div><div>I'm new to contributing to Qt directly, but I've been trying to create external C bindings for Qt for a few months now. Since C and C++ are so similar, I've recently been thinking it may just be better to add C support directly to the Qt headers by checking for the __cplusplus macro.</div><div><br></div><div>The design I was thinking of in particular was to put a function macro in qtglobals.h for creating C aliases for C++ functions (I'll call the macro QT_C_EXPORT for now).</div><div><br></div><div><font face="monospace">#ifdef __cplusplus</font></div><div><font face="monospace">#  define QT_C_EXPORT(RETURN_TYPE, A, B, PARAMS) extern "C" const auto B</font></div><div><font face="monospace">#else</font></div><div><font face="monospace">#  define QT_C_EXPORT(RETURN_TYPE, A, B, PARAMS) RETURN_TYPE B PARAMS</font></div><div><font face="monospace">#endif</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">#define QT_DEFINE_C_EXPORT</font><span style="font-family:monospace">(RETURN_TYPE, A, B, PARAMS) extern "C" const auto B = &##A</span></div><div><br></div><div>Then it can be used like this:</div><div><br></div><div>________________________________________________________________</div><div>[qpushbutton.h]</div><div><font face="monospace">#ifdef __cplusplus</font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">class QPushButton {...};</font></div></blockquote><div><font face="monospace">#else</font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">typedef struct QPushButton QPushButton;</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">QT_C_EXPORT(void, QPushButton::setFlat, QPushButton_setFlat, (bool));</font></div></blockquote><div><font face="monospace"><br></font></div><div><font face="monospace">[qpushbutton.cpp]</font></div><div><font face="monospace">// functions...</font></div><div><span style="font-family:monospace">QT_DEFINE_C_EXPORT(void, QPushButton::setFlat, QPushButton_setFlat, (bool));</span><br></div><div>________________________________________________________________<br></div><div><br></div><div>There's a couple things I still haven't figured out though, like constructors/destructors and templates. Are there solutions to these that would still allow support to be added to Qt internally or would external bindings be better?</div></div>