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

Add the possibility to disconnect all functions connected to a signal in Javascript

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Invalid
    • P3: Somewhat important
    • Some future release
    • 4.5.3
    • Qt Script
    • None

    Description

      In QWebFrame, it is possible to add a qobject to the javascript context with QWebFrame::addToJavaScriptWindowObject():
      QWebFrame::addToJavaScriptWindowObject("qobject", object):

      and connect one of its signal to a function:
      qobject.pressed.connect( function() {} );

      However, it is not possible to disconnect all the function connected to the object.

      It would be nice to be able to write
      qobject.disconnec();
      to disconnect everything.

      Here is a patch to add this behavior in QtWebkit:

      diff --git a/src/3rdparty/webkit/WebCore/bridge/qt/qt_runtime.cpp b/src/3rdparty/webkit/WebCore/bridge/qt/qt_runtime.cpp
      index 6be119c..c674552 100644
      — a/src/3rdparty/webkit/WebCore/bridge/qt/qt_runtime.cpp
      +++ b/src/3rdparty/webkit/WebCore/bridge/qt/qt_runtime.cpp
      @@ -1505,8 +1505,6 @@ JSValue QtRuntimeConnectionMethod::call(ExecState* exec, JSObject* functionObjec
      } else

      { if (d->m_isConnect) return throwError(exec, GeneralError, "QtMetaMethod.connect: no arguments given"); - else - return throwError(exec, GeneralError, "QtMetaMethod.disconnect: no arguments given"); }

      if (d->m_isConnect)

      { @@ -1530,27 +1528,35 @@ JSValue QtRuntimeConnectionMethod::call(ExecState* exec, JSObject* functionObjec connections.insert(sender, conn); }

      } else {

      • // Now to find our previous connection object. Hmm.
      • QList<QtConnectionObject*> conns = connections.values(sender);
      • bool ret = false;
        -
      • foreach(QtConnectionObject* conn, conns) {
      • // Is this the right connection?
      • if (conn->match(sender, signalIndex, thisObject, funcObject)) {
      • // Yep, disconnect it
        + if (funcObject) {
        + // Now to find our previous connection object. Hmm.
        + QList<QtConnectionObject*> conns = connections.values(sender);
        + bool ret = false;
        +
        + foreach(QtConnectionObject* conn, conns)
        Unknown macro: {+ // Is this the right connection?+ if (conn->match(sender, signalIndex, thisObject, funcObject)) { + // Yep, disconnect it + QMetaObject::disconnect(sender, signalIndex, conn, conn->metaObject()->methodOffset()); + delete conn; // this will also remove it from the map + ret = true; + break; + }+ }

        +
        + if (!ret)

        { + QString msg = QString(QLatin1String("QtMetaMethod.disconnect: failed to disconnect from %1::%2()")) + .arg(QLatin1String(sender->metaObject()->className())) + .arg(QLatin1String(d->m_signature)); + return throwError(exec, GeneralError, msg.toLatin1().constData()); + }

        + } else

        Unknown macro: { // disconnect all+ foreach(QtConnectionObject* conn, conns) { QMetaObject::disconnect(sender, signalIndex, conn, conn->metaObject()->methodOffset()); - delete conn; // this will also remove it from the map - ret = true; - break; + delete conn; } }
      • if (!ret) { - QString msg = QString(QLatin1String("QtMetaMethod.disconnect: failed to disconnect from %1::%2()")) - .arg(QLatin1String(sender->metaObject()->className())) - .arg(QLatin1String(d->m_signature)); - return throwError(exec, GeneralError, msg.toLatin1().constData()); - }

        }
        } else {
        QString msg = QString(QLatin1String("QtMetaMethod.%1: %2::%3() is not a signal"))

      Attachments

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

        Activity

          People

            kenthans Kent Hansen (Inactive)
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes