Hi,
I can’t seem to figure out how to set a timer with an asynchronous ImageProvider. The first thing I tried was
QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
QTimer::singleShot(100,this,SLOT(myTimeout()));
...
doImageProviderThings();
...
return image;
}
where myTimeout() is a slot with some implementation in MyImageProvider. Unfortunately QTimer was not able to interrupt the thread and myTimeout() executed when requestImage() returned.
Next I tried making QTimer* m_timer a member of MyImageProvider and connecting it to some signals in the MyImageProvider constructor:
MyImageProvider::MyImageProvider(QQuickImageProvider::ImageType type) :
QObject(0),
QQuickImageProvider(type, QQuickImageProvider::ForceAsynchronousImageLoading)
{
m_timer = new QTimer(this);
m_timer->setInterval(100);
m_timer->setSingleShot(true);
connect(m_timer,SIGNAL(timeout()),this,SLOT(myTimeout()));
connect(this, SIGNAL(finished()),m_timer,SLOT(stop()));
connect(this, SIGNAL(started()), m_timer, SLOT(start()));
}
QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
emit started();
...
doImageProviderThings();
...
emit finished();
return image;
}
but as far as I can tell m_timer is never even started (the signals connected in the constructor are never detected).
Lastly, I tried setting up the connections in requestImage, but the program crashed when it got the the connect() statement:
MyImageProvider::FilmImageProvider(QQuickImageProvider::ImageType type) :
QObject(0),
QQuickImageProvider(type, QQuickImageProvider::ForceAsynchronousImageLoading)
{
m_timer = new QTimer(this);
m_timer->setInterval(100);
m_timer->setSingleShot(true);
}
QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
connect(m_timer,SIGNAL(timeout()),this,SLOT(myTimeout()));
connect(this, SIGNAL(finished()),m_timer,SLOT(stop()));
connect(this, SIGNAL(started()), m_timer, SLOT(start()));
emit started();
...
doImageProviderThings();
...
emit finished();
return image;
}
I’m out of ideas. Any help would be greatly appreciated!
↧