Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. I need help with my Deno Qt/QML bindings - QGuiApplication::exec is blocking

I need help with my Deno Qt/QML bindings - QGuiApplication::exec is blocking

Scheduled Pinned Locked Moved Unsolved Language Bindings
3 Posts 2 Posters 821 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nxctr
    wrote on last edited by
    #1

    Hello,

    I've been working on my QML bindings for Deno, the new JavaScript runtime. You can view them here: https://deno.land/x/qml@v0.1.5
    But there are problems.

    First off, some things you need to know.

    • Deno has a new (unstable) FFI API for calling native code.
    • Only C functions can be used. No C++ classes.
    • Buffers (aka strings) can be passed as input parameters, but they cannot be return values.
    • Because of this, the only way to make Qt work at this time is to declare a thread_local std::unique_ptr<App> global class and initialize QGuiApplication in an init() function.
    • FFI blocks the entire Deno event loop until the function returns.
    • It uses QGuiApplication and QQmlApplicationEngine.

    The problem is that int exec() { return qGuiApp->exec(); } is blocking. I need to replace it with something like:

    while (true) {
        processQtEvents();
        if (isDone()) break;
    }
    

    No matter how hard I tried, I can't figure out how to do it!

    Things I've tried:

    QEventLoop loop;
    while (loop.isRunning()) {
        loop.processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents | QEventLoop::EventLoopExec);
    }
    
    while (true) {
        qGuiApp->processEvents(QEventLoop::AllEvents, 6000);
        if (qGuiApp->closingDown()) break;
    }
    
    qGuiApp->eventDispatcher()->processEvents(QEventLoop::AllEvents);
    

    None of them work. The most common problem is that when the window is closed, the application still keeps running (aka the only way to end it is with CTRL+C). Signals such as QQmlApplicationEngine::quit and QQmlApplicationEngine::exit do not fire either.

    I even tried making everything live in a global C++ thread class (not QThread) and passing data using mutexes and conditional variables, so that I could just have qGuiApp->exec() running in a separate thread and call isDone() from Deno. Still doesn't work. ThreadedApplication::operator()() and ThreadedApplication::setData() are in different threads, which Qt hates.

    In simplest terms: can QGuiApplication::exec() be replaced with a while() loop?

    I apologize if I'm not being clear about something. I'm at wits end to try and figure this out.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Did you try to integrate Qt's event loop with the one from Deno ?

      AFAIK, QAbstractEventDispatcher is the starting for that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Did you try to integrate Qt's event loop with the one from Deno ?

        AFAIK, QAbstractEventDispatcher is the starting for that.

        N Offline
        N Offline
        nxctr
        wrote on last edited by
        #3

        @SGaist Thanks for the reply. Unfortunately, Deno's event loop isn't exposed, at all. It's just calling functions from a C ABI using dlopen().

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved