简体   繁体   中英

Change QQuickImage source from within Q_INVOKABLE function or slot

I have a very simple task that has resulted in going around in circles mainly because of the separation of QML and C++ side of QT. So instead of asking specific QT questions I need general advice on what QT and QML functions I should use to achieve my usecase.

Usecase:

A QQuickControls UI allows a user to select an image. That image is shown in the UI. When the user clicks the button 'Process' the application finds edges.

My question is; how can I overwrite the currently being shown image? Should I use a Q_INVOKABLE function? Or a signal or slot? My below code has created the UI, allows a user to select an image (and displays it), generates the edge image when the 'Process' button is clicked. It just doesn't display that new edge image because I don't know how to achieve this in QT/QQuickControls2.

Any advice how to implement this in QT would be greatly appreciated.

What we have:

  • QML UI with a placeholder for the image and the button to trigger new image.
  • C++ ImageProcessor QML type for generating the new image from OpenCV Mat.

The easiest solution would be:

Mind that there a few more solutions for more dynamic rendering with QQuickFramebufferObject and QQuickpainteditem and QAbstractVideoSurface that worth effort when the image is not static etc.

PS I also suggest you to rename the question as long as it is not really about how exactly to execute C++ code from QML but how to make a QML-compatible image and actually render it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM