Congratulations to our 2022 Qt Champions!

Block JS execution in same thread -- is it possible?

  • My Qt app is intended for a mobile platform, i.e. there are no windows, and dialog boxes are created as a bunch of Rectangles on top of the rest. I wrote a dialog that allows the user to make some choice. The dialog first creates a semi-transparent Rectangle covering the entire screen and eating up all mouse events, effectively making the fake-dialog modal.

    In the current implementation, the call that opens the dialog can't directly read the result. Instead, the dialog passes the result back through a signal/slot mechanism. This works, but is somehow clumsy. It would be much nicer if I could simply write in Jawa-Script: [btw, why does this editor remove JS when correctly spelled?!]

    var result = App.showChoiceDlg();
    console.log ("And the result is: " + result);

    This means that showChoiceDlg() needs to block execution of the script until some event occurs. I wonder if this is possible? And how?

    EDIT: For clarification: App is a custom C++ class, which I made visible to QML through QQmlContext's setContextProperty method. showChoiceDlg() is a public slot in that C++ class, which dynamically loads my dialog QML file and adds it to some main container.

Log in to reply