-
Notifications
You must be signed in to change notification settings - Fork 18
add support to return value from slot #33
Comments
The problem rises from the memory handling -- if it is not a reference, value will take memory and leak it every time this slot will be called |
is this also true for primitive datatypes like in this case it means there is no feasible way to return results to qml without building a custom |
@fneddy all primitives are wrapped in QVariants. Yes, if it's not possible to return a reference, there should be some kind of garbage collector system, which is, hopefully, can be provided via |
A straightforward way of doing this (I think I made it this way in |
so I had a little time to investigate: The slot definition struct has a field for the return type of the slot. In the Q_OBJECT macro this return value is hardcoded to 43 this corresponds to QMetaType::Void.
this I because is is coded this way. But does it need to be so? The slot definition allows all predefined QMetaTypes as return types.
I think this should be only true for rust structs. QVariant will try to clear the Object but through this are non C++ QObjects this will have no effect an leak(?). All trough for the pre-defined QMetaTypes QVariant should be totally able to free the memory(!?) So long story short: in my opinion returning a non QVariant should be OK as long as its type is defined as std QMetaType. This way QT should know how to handle free/delete. For every other datatype there must be either a garbage collector or a callback from the QVariant ~destructor that calls the rust struct drop() method. |
is it possible to return
Option<QVariant>
instead ofOption<&QVariant>
from a slot?if not we should add support for it to make it possible to return local values.
currently it does not compile:
The text was updated successfully, but these errors were encountered: