[PyQt] Custom C++ types as signal arguments

Phil Thompson phil at riverbankcomputing.com
Sat Sep 28 13:29:03 BST 2013


On Tue, 24 Sep 2013 13:24:05 +0000 (UTC), David Boddie <davidb at met.no>
wrote:
> I'm running into problems with sip and custom signal arguments. I'm
> probably
> doing something wrong, and I'm hoping that someone might be able to put
me
> on
> the right track.
> 
> I've written a class with this definition:
> 
>   #include <string>
>   #include <vector>
>   #include <QWidget>
> 
>   typedef std::vector<std::string> StringList;
> 
>   class Emitter : public QWidget
>   {
>       Q_OBJECT
> 
>   public:
>       Emitter(QWidget *parent = 0);
>       virtual ~Emitter();
> 
>   signals:
>       void emitStrings(StringList);
>       void emitStr(std::string, std::string);
>       void emitQString(QString);
>   };
> 
> My sip wrapper starts with a typedef for the StringList type and
> %MappedType
> implementations for std::string and StringList:

Remove this typedef...

>   typedef std::vector<std::string> StringList;
> 
>   %MappedType std::string
>   {
>   %TypeHeaderCode
>   #include <string>
>   %End
> 
>   ...
>   };
> 
>   %MappedType StringList
>   {
>   %TypeHeaderCode
>   #include <iostream>
>   #include <string>
>   #include <vector>
>   typedef std::vector<std::string> StringList;
>   %End
> 
>   ...
>   };
> 
> It also has this definition for the Emitter class:
> 
>   class Emitter : public QWidget
>   {
>   %TypeHeaderCode
>   #include "Emitter.h"
>   %End
> 
>   public:
>     Emitter(QWidget *parent = 0);
>     virtual ~Emitter();
> 
>   signals:
>     void emitStrings(StringList);
>     void emitStr(std::string, std::string);
>     void emitQString(QString);
>   };
> 
> This all builds correctly, but the emitStrings signal does not appear to
> work
> correctly, causing a crash when accessed in apparently any way at all.
Even
> evaluating the signal object fails.
> 
> Some elementary debugging indicates that the bound_overload member of
the
> qpycore_pyqtBoundSignal object is zero for this signal, and maybe this
> leads to
> the crash when trying to connect the signal to a slot.
> 
> I'm using PyQt 4.9.1 and sip 4.13.2. I've attached a simple project to
> demonstrate the problem.
> 
> David

SIP should probably complain about the typedef as you are effectively
providing two definitions for StringList.

Also in the current snapshot at least, you get a sensible exception.

Thanks,
Phil


More information about the PyQt mailing list