Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140832

Qt Quick for Rust: Get rid of QObjectHolder in public API

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P1: Critical P1: Critical
    • None
    • 6.11
    • Qt Bridges
    • None

      Currently we need to create QObjectHolders to add the QMetaObject to a Rust structure, e.g.

      let mut backend = QObjectHolder::new(Backend::default());
      
      let _app = QGuiApplication::new();
      let mut qml_engine = QQmlApplicationEngine::new();
      
      let mut properties = QVariantMap::default();
      properties.insert("backend", &backend.as_qobject_mut().into());
      qml_engine.pin_mut().set_initial_properties(&properties); 

      The QObjectHolder consumes the Backend.

      This has some drawbacks:
      1) Our users need to create a QObjectHolder manually. If they do not, the application might crash.

      2) The inner Backend is not accessible anymore from the Rust side. So all modifications have to be triggered from the QML side. This way it is difficult to update the UI from the Rust side, if there is no QML event involved.

      It would be great if

      1) We could have the QObject both on Rust and QML side at the same time. The Rust pattern for this is probably RC<>/RefCell<>.

      2) The QObjectHolder is created implicitly in the QObject constructors and hidden from our users. It can be pulled out when we have to create a QVariant. This way our users do not have to deal with it and no accidents can happen. 

       

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            yuri.knigavko Yuri Knigavko
            matthias_rauter Matthias Rauter
            Alex Blasche Alex Blasche
            Vladimir Minenko Vladimir Minenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes