Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-58133

Crash on emitting a signal from C++ to QML with undefined QJSValue

    XMLWordPrintable

Details

    Description

      Hi,

      I am the author of a library called QuickFlux (www.github.com/benlau/quickflux ) . One of the function is a central message dispatcher for component-to-component communication that avoid to propagate a signal across uncertain amount of components .

      I just got a bug report that it will crash on Qt 5.7.1/5.8RC in Mac/Windows (but works with Qt 5.7.0) . After traced out the code, I found that it happen when emitting a signal from C++ to QML with a QJSValue (isUndefined() == true) as argument.

      For example, if we have such C++ class:

      class Messenger : public QQuickItem
      {
          Q_OBJECT
      public:
          explicit Messenger(QQuickItem *parent = 0);
      
      signals:
          void received(QJSValue message);
      
      public slots:
          void send (QJSValue message = QJSValue());
      };
      

      The send() function is actually a proxy to forward the message

      void Messenger::send(QJSValue message)
      {
          emit received(message);
      }
      

      Then call send() in QML, the program will crash immediately

          Messenger {
              id: messenger
              onReceived: {
                  console.log("hello");
              }
          }
      
          Component.onCompleted: {
              messenger.send(); // crash here
          }
      

      Part of backtrace:

      QML debugging is enabled. Only use this in a safe environment.
      Error: signal 11:
      0   qtbug                               0x000000010add87a2 _Z15handleBacktracei + 34
      1   libsystem_platform.dylib            0x00007fffe45c2bba _sigtramp + 26
      2   ???                                 0x000000011684e7ad 0x0 + 4672776109
      3   QtQml                               0x000000010b33f39d _ZN15QQmlBoundSignal10setEnabledEb + 477
      4   QtQml                               0x000000010b38106d _ZN12QQmlNotifier10emitNotifyEP20QQmlNotifierEndpointPPv + 781
      5   QtCore                              0x000000010b850fc9 _ZN11QMetaObject8activateEP7QObjectiiPPv + 121
      6   qtbug                               0x000000010addac4f _ZN9Messenger8receivedE8QJSValue + 63
      

      The program and backtrace has been attached .

      Thanks

      Attachments

        1. backtrace.log
          3 kB
          Ben Lau
        2. qtbug.zip
          3 kB
          Ben Lau
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            benlau Ben Lau
            Votes:
            3 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews