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

QtBridges-Python: Expose Signals

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • None
    • Qt Bridges
    • None

      Implement a way so that the user can emit Qt Signals from the Python data model. The handling of the signals will be done in QML. If the signals are not handled in QML, a warning will be produced that the signal is not handled in QML.

      Current idea is to expose a function to Python code

      def emit(signal_name: str, *args) -> None:​

       

      Example:
      // Python code

      class FileDownloaderModel:
          def __init__(self):
              super().__init__()
      
          def download_file(self, url: str) -> None:
              print(f"Downloading {url}")
              # this call onDownloadCompleted in QML
              emit_signal("downloadCompleted", url) #infer type from Url or use QVariant
      
      downlaoder = FileDownloaderModel()
      AutoQmlBridge(downloader, data_type="List")
      

      // QML Code

      import QtQuick 2.15
      import QtQuick.Controls 2.15
      import backend 1.0
      
      ApplicationWindow {
          ...
      
          Connections {
              target: FileDownloaderModel
              onDownloadCompleted: {
                  console.log("Download completed for: " + url)
              }
          }
      }
      
      

       

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

            shpremna Shyamnath Premnadh
            shpremna Shyamnath Premnadh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes