Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manipulate QML Canvas from C++ in Qt5

In my Qt5 application I have some C++ and some QML working in harmony (aka sending signals back and forth).

At this point I want to implement a widget that shows a real-time updated visualization of a playing audio stream in forms of the actual waveform showing in my QML. So I wonder which alternatives ways exist to solve this? What is the easiest alternative to code and which alternative has the best performance?

My naive ideas are:

  • Create a Canvas in my QML and then draw directly to this canvas from C++
  • Send actual samples as a buffer to QML and draw them in canvas from js
  • Send actual samples as a buffer to QML and draw them in some other manner
  • Write a custom C++ widget and somehow display that in QML

PS: I already have access to the actual samples to generate the visualization from, however if you have a clever solution to this as well then I would be overjoyed!

Thanks

like image 547
Lennart Rolland Avatar asked Jan 29 '15 03:01

Lennart Rolland


1 Answers

You could subclass QQuickItem. Also, there is a subclass, QQuickPaintedItem that allows you to draw with a QPainter.

Here you have an example of QQuickPaintedItem usage

like image 173
Smasho Avatar answered Oct 07 '22 01:10

Smasho