Im tring to update a qml Image URL via signal:

This is working perfectly fine when executed in this method:

Qt Code:
  1. void Sentinel::startQmlEngine()
  2. {
  3. QQmlApplicationEngine qmlEngine;
  4.  
  5. qmlRegisterType<ImageItem>("ImageItem",1,0,"ImageItem");
  6. qmlEngine.rootContext()->setContextProperty("imageUrlClass", &image);
  7.  
  8. QQmlComponent component(&qmlEngine, "qrc:/main.qml");
  9. object = component.create();
  10. assert(object);
  11.  
  12. image.setUrl(getPathToImage());
  13. }
To copy to clipboard, switch view to plain text mode 

As soon as I outsource setting the URL the signal is not emitted

Qt Code:
  1. void Sentinel::updateGui()
  2. {
  3. image.setUrl(getPathToImage());
  4. }
To copy to clipboard, switch view to plain text mode 

How can this be?

Here my Qml

Qt Code:
  1. import QtQuick 2.12
  2. import QtQuick.Window 2.12
  3. import ImageItem 1.0
  4.  
  5.  
  6. Rectangle {
  7.  
  8. width: 768
  9. height: 576
  10.  
  11. Connections {
  12. target: imageUrlClass
  13. onUrlChanged: {
  14. image.update();
  15. console.log("image UURL-" + imageUrlClass.imageUrl);
  16. }
  17. }
  18.  
  19. Image {
  20. id: image
  21. objectName: "image"
  22. x: 0
  23. y: 0
  24. width: 768
  25. height: 576
  26. source: imageUrlClass.imageUrl
  27. opacity: 1
  28. clip: true
  29. fillMode: Image.PreserveAspectFit
  30. cache: false
  31. }
  32.  
  33. }
To copy to clipboard, switch view to plain text mode 

ImageItem class header:

Qt Code:
  1. #pragma once
  2.  
  3. #include <QQuickPaintedItem>
  4.  
  5. //---------------------------------------------------------------------------
  6.  
  7.  
  8. class ImageItem: public QQuickPaintedItem
  9. {
  10. Q_OBJECT
  11. Q_PROPERTY(QVariant imageUrl READ getUrl() WRITE setUrl NOTIFY urlChanged)
  12.  
  13. public:
  14.  
  15. explicit ImageItem(QQuickItem *parent = nullptr);
  16.  
  17. virtual void paint(QPainter* painter);
  18.  
  19. QVariant getUrl() const;
  20. void setUrl(const QVariant &value);
  21.  
  22. signals:
  23.  
  24. void urlChanged();
  25.  
  26. private:
  27. QVariant url;
  28.  
  29. };
To copy to clipboard, switch view to plain text mode 

And Cpp:

Qt Code:
  1. #include "ImageItem.h"
  2.  
  3. //---------------------------------------------------------------------------
  4.  
  5. ImageItem::ImageItem(QQuickItem *parent) :
  6. QQuickPaintedItem(parent)
  7. {
  8. }
  9.  
  10. QVariant ImageItem::getUrl() const
  11. {
  12. return url;
  13. }
  14.  
  15. void ImageItem::setUrl(const QVariant &value)
  16. {
  17. url = value;
  18. emit urlChanged();
  19. }
  20.  
  21. void ImageItem::paint(QPainter* painter)
  22. {
  23. paint(painter);
  24. }
To copy to clipboard, switch view to plain text mode 

Thanks!