[PyQt] Custom C++ types as signal arguments

David Boddie davidb at met.no
Tue Sep 24 14:24:05 BST 2013


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:

  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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyqt-test-bound-signals.zip
Type: application/zip
Size: 4566 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130924/fe24a5f6/attachment.zip>


More information about the PyQt mailing list