Skip to content

Instantly share code, notes, and snippets.

@robertknight
Created April 23, 2013 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertknight/5445289 to your computer and use it in GitHub Desktop.
Save robertknight/5445289 to your computer and use it in GitHub Desktop.
Workaround for https://bugs.webkit.org/show_bug.cgi?id=75984 - adds a wrapper around QtObject.method.connect() which registers the method in an array and disconnects the method when the document is unloaded.
<html>
<body>
<script>
// wrappers around QtObject.methodName.connect()
// workaround for https://bugs.webkit.org/show_bug.cgi?id=75984
window.qtSignals = [];
// connect a Qt signal to a JS function and register it for disconnection
// when the document is unloaded
function connectQtSignal(signal, func) {
var conn = {signal : signal, receiver : func};
window.qtSignals.push(conn);
signal.connect(func);
}
window.addEventListener('unload', function() {
window.qtSignals.forEach(function(connection) {
connection.signal.disconnect(connection.receiver);
});
window.qtSignals = [];
});
window.addEventListener('load', function() {
connectQtSignal(myObject.aSignal, function() {
console.log('signal emitted');
});
});
</script>
<div style="width:300px;height:300px;">Test Content</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment