<div dir="auto">Hi Julien,<div dir="auto"><br></div><div dir="auto">For the sake of clarity, you might want to filter out what is specific to QGIS syntax, mainly all the SIP_* macros.</div><div dir="auto">The sipify script is a QGIS internal and not known further.</div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 1 Apr 2021, 11:58 Julien Cabieces, <<a href="mailto:julien.cabieces@oslandia.com">julien.cabieces@oslandia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi,<br>
<br>
I would like to define an interface (abstract class) where one method is<br>
pure virtual and takes a std::function as a parameter.<br>
<br>
I have this in my C++ header<br>
<br>
```<br>
class MyInterface<br>
{<br>
public:<br>
<br>
#ifndef SIP_RUN<br>
virtual MyObject *doThings( const QString &filePath, const QUrl &url,<br>
const std::function<void ( const QString & )> &errorCallback = {} ) = 0 ;<br>
#else<br>
virtual MyObject *doThings( const QString &filePath, const QUrl &url, SIP_PYCALLABLE / AllowNone / ) = 0;<br>
% MethodCode<br>
{<br>
Py_BEGIN_ALLOW_THREADS<br>
<br>
sipCpp->MyInterface::doThings( *a0, *a1, [a2]( const QString & error )<br>
{<br>
SIP_BLOCK_THREADS<br>
Py_XDECREF( sipCallMethod( NULL, a2, "D", &error, sipType_QString, NULL ) );<br>
SIP_UNBLOCK_THREADS<br>
} );<br>
<br>
sipRes = sipCpp;<br>
<br>
Py_END_ALLOW_THREADS<br>
}<br>
% End<br>
#endif<br>
```<br>
<br>
and this in the corresponding sip file<br>
<br>
```<br>
class MyInterface<br>
{<br>
<br>
%TypeHeaderCode<br>
#include "myinterface.h"<br>
%End<br>
public:<br>
<br>
virtual MyObject *doThings( const QString &filePath, const QUrl &url, SIP_PYCALLABLE / AllowNone / ) = 0;<br>
%MethodCode<br>
{<br>
Py_BEGIN_ALLOW_THREADS<br>
<br>
sipCpp->MyInterface::doThings( *a0, *a1, [a2]( const QString & error )<br>
{<br>
SIP_BLOCK_THREADS<br>
Py_XDECREF( sipCallMethod( NULL, a2, "D", &error, sipType_QString, NULL ) );<br>
SIP_UNBLOCK_THREADS<br>
} );<br>
<br>
sipRes = sipCpp;<br>
<br>
Py_END_ALLOW_THREADS<br>
}<br>
%End<br>
<br>
};<br>
```<br>
<br>
I end up with the following compilation errors<br>
<br>
```<br>
error: non-virtual member function marked 'override' hides virtual member function<br>
::MyObject* doThings(const ::QString&,const ::QUrl&,PyObject *) SIP_OVERRIDE;<br>
<br>
hidden overloaded virtual function 'MyInterface::doThings' declared here: type mismatch at 3rd parameter ('const std::function<void (const QString &)> &' vs 'PyObject *' (aka '_object *'))<br>
virtual MyObject *doThings( const QString &filePath, const QUrl &url,<br>
^<br>
error: allocating an object of abstract class type 'sipMyInterface'<br>
sipCpp = new sipMyInterface();<br>
^<br>
note: unimplemented pure virtual method 'doThings' in 'sipMyInterface'<br>
virtual MyObject *doThings( const QString &filePath, const QUrl &url,<br>
```<br>
<br>
The errors make sense to me because the sip doThings version has not the<br>
same signature than the original Cpp one (Callable vs std::function) but<br>
I fail to understand how to fix this.<br>
<br>
Kind regards,<br>
Julien<br>
</blockquote></div>