Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-3176

error: 'PySide::Signal' has not been declared @ PySide::Signal::registerSignals

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.9.1
    • Shiboken

      shiboken generates broken C++ code

      [ 87%] Building CXX object CMakeFiles/KTextEditor.dir/KTextEditor/ktexteditor_view_wrapper.cpp.o
      /build/ktexteditor-pyside6-binding/build/KTextEditor/ktexteditor_view_wrapper.cpp:2896:13: error: no member named 'Signal' in namespace 'PySide'
       2896 |     PySide::Signal::registerSignals(pyType, &::KTextEditor::View::staticMetaObject);
            |     ~~~~~~~~^
      /build/ktexteditor-pyside6-binding/build/KTextEditor/ktexteditor_document_wrapper.cpp:4377:13: error: no member named 'Signal' in namespace 'PySide'
       4377 |     PySide::Signal::registerSignals(pyType, &::KTextEditor::Document::staticMetaObject);
            |     ~~~~~~~~^

      reproduction
      https://github.com/milahu/ktexteditor-pyside6

      git clone https://github.com/milahu/ktexteditor-pyside6
      cd ktexteditor-pyside6
      git checkout 0c7b8eec940efc95c0ef8b17a26a51b5a19e7a79
      nix-build

      ... or instead of nix-build

      cmake -S . -B build  -Dpython_interpreter=$(which python)
      cd build
      make

      bindings.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <typesystem package="KTextEditor">
       <load-typesystem name="typesystem_core.xml" generate="no" />
       <namespace-type name="KTextEditor">
        <object-type name="Editor"></object-type>
        <object-type name="Document"></object-type>
        <object-type name="View"></object-type>
        <object-type name="Cursor"></object-type>
        <enum-type name="EditorOption"></enum-type>
       </namespace-type>
      </typesystem> 
      

      generated code
      KTextEditor/ktexteditor_view_wrapper.cpp

      PyTypeObject *init_KTextEditor_View(PyObject *enclosingClass)
      {
         // ...
      
         MultipleInheritanceInitFunction func = Sbk_KTextEditor_View_mi_init;
         Shiboken::ObjectType::setMultipleInheritanceFunction(Sbk_KTextEditor_View_TypeF(), func);
          Shiboken::ObjectType::setCastFunction(Sbk_KTextEditor_View_TypeF(), &Sbk_KTextEditor_ViewSpecialCastFunction);
          // FIXME error: no member named 'Signal' in namespace 'PySide'
          PySide::Signal::registerSignals(pyType, &::KTextEditor::View::staticMetaObject);
          qRegisterMetaType< ::KTextEditor::View *>();
      
          return pyType;
      } 

      generated from View(ViewPrivate *impl, QWidget *parent);
      https://invent.kde.org/frameworks/ktexteditor/-/blob/master/src/include/ktexteditor/view.h#L320
      with implementation in KTextEditor::ViewPrivate::ViewPrivate
      https://invent.kde.org/frameworks/ktexteditor/-/blob/master/src/view/kateview.cpp#L107

      class KTEXTEDITOR_EXPORT View : public QWidget, public KXMLGUIClient
      {
          Q_OBJECT
      
      protected:
          /*!
           * Constructor.
           *
           * Create a view attached to the widget \a parent.
           *
           * Pass it the internal implementation to store a d-pointer.
           *
           * \a impl is the d-pointer to use
           *
           * \a parent is the parent widget
           *
           * \sa Document::createView()
           */
          View(ViewPrivate *impl, QWidget *parent);

      blame CppGenerator::writeSignalInitialization
      https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/shiboken6/generator/shiboken/cppgenerator.cpp#n5648

      void CppGenerator::writeSignalInitialization(TextStream &s, const AbstractMetaClassCPtr &metaClass)
      {
          // Try to check something and print some warnings
          const auto &signalFuncs = metaClass->cppSignalFunctions();
          for (const auto &cppSignal : signalFuncs) {
              if (cppSignal->declaringClass() != metaClass)
                  continue;
              const AbstractMetaArgumentList &arguments = cppSignal->arguments();
              for (const AbstractMetaArgument &arg : arguments) {
                  const AbstractMetaType &metaType = arg.type();
                  const QByteArray origType =
                      QMetaObject::normalizedType(qPrintable(metaType.originalTypeDescription()));
                  const QByteArray cppSig =
                      QMetaObject::normalizedType(qPrintable(metaType.cppSignature()));
                  if ((origType != cppSig) && (!metaType.isFlags())) {
                      QString msg = "Typedef used on signal "_L1 + metaClass->qualifiedCppName()
                                    + "::"_L1 + cppSignal->signature();
                      ReportHandler::addGeneralMessage(msg);
                  }
              }
          }
      
          s << "PySide::Signal::registerSignals(pyType, &" << m_gsp
             << metaClass->qualifiedCppName() << "::staticMetaObject);\n";
      } 

      chatGPT says:

      PySide::Signal::registerSignals is old pyside2 code

      "There is no official public API in Shiboken6 6.9.1 that replaces PySide::Signal::registerSignals."

      "PySide::Signal was removed in PySide6 6.x headers"

      some blog posts suggest switching to Shiboken::initQObjectSubType
      but that only works with some patched shiboken versions

      "Use a Shiboken6 version that still provides PySide::Signal::registerSignals, e.g., PySide6 6.5 or earlier.
      This is less ideal — you lose new PySide6 features."

      workaround: add a stub for PySide::Signal::registerSignals

      namespace PySide {
          inline void Signal::registerSignals(PyTypeObject*, const QMetaObject*) {}
      }

      problem:
      "signals won’t be connected, so Python slots won’t work"

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            milahu milan hauth
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes