Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when using QObject in Python #85

Open
egfconnor opened this issue Sep 29, 2017 · 4 comments
Open

Segmentation fault when using QObject in Python #85

egfconnor opened this issue Sep 29, 2017 · 4 comments

Comments

@egfconnor
Copy link

egfconnor commented Sep 29, 2017

Initial comments were wrong. See later comments.

@thp
Copy link
Owner

thp commented Oct 14, 2017

Do you call it from a different thread? Can you create a SSCCE to reproduce this issue? Also, on which version / platform / OS are you experiencing this issue? Can you run it in gdb or lldb (or any other debugger) and see where it crashes?

@egfconnor
Copy link
Author

egfconnor commented Nov 14, 2017

I'm attempting to narrow this down to a minimal sample that reproduces it but figured I'd give some info that might be related or might not.

I have a translation class that is a QObject that I use for gettext translations. I set it as a context property and use it throughout QML and to allow the same pipeline for Python I used Pyotherside to store the method in Python for use there.

QML setting the QObject to find the function from:
call_sync('translator.set_translator', [applicationWindow])

QML translate function:

function translate(text) {
    return translator.getTranslation(text)
}

main.cpp:
engine.rootContext()->setContextProperty("translator", &translationService);

translation_service.cpp:
QString TranslationService::getTranslation(QString translation) { return "test"; }

In Python I reference the QML method by:

import pyotherside

__translate__ = None


def set_translator(translator):
    global __translate__
    __translate__ = translator.translate


def get_translation(text):
    if __translate__ != None:
        return  __translate__(text)
    else:
        return text

In Python I've created a loop that calls this method repeatedly:

def test_function():
    while True:
        trans = translator.get_translation("Study date")

This will crash almost immediately. I'm not sure this is my root problem but it might be a different problem I've found. If I add some time.sleep() calls or don't call it so much it is fine.

@egfconnor
Copy link
Author

Okay I've finally figured out this issue. Any time I try and access a QObject that's passed into Python I can have it crash. It's not every time though.

I'm currently using QObjects in Python for 2 use cases. The first is the translator functionality above where I was storing a QML function to use in Python. The other case was I was passing a Popup window with a cancel property on it and in Python if the user ever set that boolean property to false I would cancel what I was doing in Python.

I will create a small project that shows it shortly here.

@egfconnor egfconnor changed the title Segmentation fault when using pyotherside.send Segmentation fault when using QObject in Python Nov 15, 2017
@thp
Copy link
Owner

thp commented Jun 6, 2019

Can you get a backtrace of the crash? Using e.g. gdb or lldb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants