grabToImage ready connection problems
Unsolved
General and Desktop
-
Re: Connecting a slot to a QSharedPointer (QQuickItem::grabToImage)
Hi,
I am trying to grabToImage on a QQuickItem that is pointed out by qml. But the connection in the cpp-file never gets triggered? My guess is that it is quick and gets triggered before the connection is created? If so, how can the connection be set up before calling grabToImage? Or is it something else that is faulty in this code?The only thing printed out when this programis executed is:
grabImage, m_sourceItem = QQuickItem(0x65ac80, parent=0x6ce490, geometry=0,0 100x80)cpp-file (only more relevant parts shown) for C++ component
void QmlImageGrabber::grabImage(){ //qDebug below prints out: //grabImage, m_sourceItem = QQuickItem(0x65ac80, parent=0x6ce490, geometry=0,0 100x80) qDebug() << "grabImage, m_sourceItem =" << m_sourceItem; m_imageGrabResult = m_sourceItem->grabToImage().data(); connect(m_imageGrabResult, &QQuickItemGrabResult::ready, this, &QmlImageGrabber::grabImageReady); } void QmlImageGrabber::grabImageReady(){ qDebug() << "This is never printed out!"; //connection purpose fullfilled, disconnect disconnect(m_imageGrabResult, &QQuickItemGrabResult::ready, this, &QmlImageGrabber::grabImageReady); //Here I will do something more emit sourceChanged(); }
h-file for C++ component
class QmlImageGrabber : public QObject { Q_OBJECT Q_PROPERTY(QQuickItem *source READ source WRITE setSource NOTIFY sourceChanged); public: QmlImageGrabber(); ~QmlImageGrabber(); QQuickItem* source(); void setSource(QQuickItem *source); signals: void sourceChanged(); private: void grabImage(); void grabImageReady(); QQuickItem *m_sourceItem = nullptr; QQuickItemGrabResult *m_imageGrabResult = nullptr; };