Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Sending signals in QML accross thread boundaries
Forum Update on Monday, May 27th 2025

Sending signals in QML accross thread boundaries

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 178 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.
  • M Offline
    M Offline
    masi32
    wrote on last edited by
    #1

    Dear firends,
    I'm designing application which takes advantage of QML and JavaScript. One of my goal is to make application user scriptable. The application itself can be considered as "chassis" for low level communication (usb, ethernet, serial...) and GUI designed solely in QML.

    And the goal is to add ability of running user scripts, which should be as simple as possible to learn. You can imagine them for example like simple loop, which acquires some data, adds them to graph, waits 30seconds, do it again in loop.

    As I want to keep this scripts simple, I don't want to introduce any event driven algorithms, like hooking to timers, adding async IO (some commands may execute more than 1s). But on the other hand, I want to keep GUI responsive.

    So far, I've tried to use WorkerScipt to accomplish this task. I've added things like delay, file ops, comm via C++ classes and it works fairly well. But there are two limitations:

    1. As far as I know WorkerScript unfortunately does not have any signal, which could interrupt internal engine from deadlock - like if user executes "while(1){}".

    2. Limited communication interface with main/gui thread.

    So I'm now investigating possibility of using C++ threads, which would run another instance of QQMLEngine. This would solve issue no 1 - by using setInterrupted member function.

    But the purpose of this post is to ask you for advice, how to implement communication between these two qmlEngines in best possible and most universal manner.

    In some post I've read, that sending signals across thread boundary is possible. I definitely know that, at least in C++ (by queued signals). But not sure about QML.

    So far I did not find any way how to do it (and not sure if it is actually possible). I can create QtObject in QML, which has signals connectable to other QML components and emit these signals from user defined JavaScript scripts - works great. But only within one thread.

    So is there any way how to do it? For example share above mentioned QtObject between two qmlEngines? Or by sharing some global object? Or context?

    I can definitely imagine of using C++ designed bridge - create two C++ classes, which would expose some interface to both threads and using C++ mechanism (queued connection) to perform this. But I want this functionality to be extensible just by QML and JavaScript, not by compiled code. As this would be required by adding new signals to C++ class.

    Or do you have any other ideas how to solve this task?

    Thank you and best regards

    Petr

    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