binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Document python ui code pitfalls

Open negasora opened this issue 9 months ago • 0 comments

Namely that you have to hold references to intermediate objects, so instead of

import binaryninjaui
print(binaryninjaui.UIContext.activeContext().getCurrentView().actionContext().token.token)

you have to do

import binaryninjaui
ui_context = binaryninjaui.UIContext.activeContext()
view = ui_context.getCurrentView()
action_context = view.actionContext()
token = action_context.token
print(token.token)

See also: https://doc.qt.io/qtforpython-6/shiboken6/typesystem_ownership.html#not-saving-unowned-objects-references

negasora avatar May 23 '25 13:05 negasora