I am working on a c++/QML with Opencv Project..
I have found that the best way to view the processed image in QMl is to write a custom QML component that extends QQuickPaintedItem
in c++ and it is working well:
class ImageView : public QQuickPaintedItem{
Q_OBJECT
Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged)
public:
// I need to pass a pointer of ImageService
ImageView(QQuickItem *parent = nullptr, ImageService *imageService = nullptr);
Q_INVOKABLE void updateImage();
void paint(QPainter *painter);
QImage image() const;
signals:
void imageChanged();
private:
QImage m_image;
ImageService *m_imageService;
};
and I registered this type in C++ like the following :
qmlRegisterType<ImageView>("opencv.plugin", 1, 0, "ImageView");
My Problem is :
I have this class ImageService
that does all the work and holds the last version of the image after processing:
class ImageService
{
public:
ImageService();
bool openImage(const std::string &);
QImage toQImage();
bool isValid();
private:
std::string m_imagePath;
cv::Mat m_image;
};
I need ImageView
component to update itself after any operation that ImageService
perform using updateImage()
function.
I tried : I thought about:
- passing a pointer to
ImageService
to ImageView, But I do not see how. - Making ImageService as
Qml Property
and pass a QML Image from Qml to theImageView
component,But I do not think that it is a good idea.