mirror of
https://github.com/thp/pyotherside.git
synced 2025-01-28 23:52:55 +08:00
Allow calling signals from Python (Fixes #98)
This commit is contained in:
parent
067e3a618d
commit
dab1576bb1
@ -390,6 +390,20 @@ pyotherside_QObjectMethod_call(PyObject *callable_object, PyObject *args, PyObje
|
||||
QMetaMethod method = metaObject->method(i);
|
||||
|
||||
if (method.name() == ref->method()) {
|
||||
if (method.methodType() == QMetaMethod::Signal) {
|
||||
// Signals can't be called directly, we just return true or
|
||||
// false depending on whether method.invoke() worked or not
|
||||
bool result = method.invoke(o, Qt::AutoConnection,
|
||||
genericArguments.value(0),
|
||||
genericArguments.value(1), genericArguments.value(2),
|
||||
genericArguments.value(3), genericArguments.value(4),
|
||||
genericArguments.value(5), genericArguments.value(6),
|
||||
genericArguments.value(7), genericArguments.value(8),
|
||||
genericArguments.value(9));
|
||||
|
||||
return convertQVariantToPyObject(result);
|
||||
}
|
||||
|
||||
QVariant result;
|
||||
if (method.invoke(o, Qt::DirectConnection,
|
||||
Q_RETURN_ARG(QVariant, result), genericArguments.value(0),
|
||||
|
5
tests/test_call_signal/TestModule.py
Normal file
5
tests/test_call_signal/TestModule.py
Normal file
@ -0,0 +1,5 @@
|
||||
import pyotherside
|
||||
|
||||
def makeCalls(obj):
|
||||
print(f'result of callFunction: {obj.callFunction()}')
|
||||
print(f'result of callSignal: {obj.callSignal()}')
|
31
tests/test_call_signal/test.qml
Normal file
31
tests/test_call_signal/test.qml
Normal file
@ -0,0 +1,31 @@
|
||||
import QtQuick 2.9
|
||||
import io.thp.pyotherside 1.5
|
||||
|
||||
Item {
|
||||
id: obj
|
||||
|
||||
signal callSignal()
|
||||
|
||||
function callFunction() {
|
||||
print('Function Called')
|
||||
return 'hoho'
|
||||
}
|
||||
|
||||
function signalConnection(){
|
||||
print('Signal Called')
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
obj.callSignal.connect(signalConnection)
|
||||
}
|
||||
|
||||
Python {
|
||||
Component.onCompleted: {
|
||||
addImportPath(Qt.resolvedUrl('.'));
|
||||
|
||||
importModule('TestModule', function(){
|
||||
call('TestModule.makeCalls', [obj])
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user