Details
-
Suggestion
-
Resolution: Invalid
-
P3: Somewhat important
-
4.5.3
-
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)
{ @@ -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; + }+ }+
{ + 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()); + }
+ if (!ret)+ } 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"))