PDA

View Full Version : QFutureWatcher finished without even starting a QFuture...



Zweistein
22nd September 2011, 14:30
Hi,
my Problem is the other way round in comparisson to the most other users having kind of the same problem :)

My QFutureWacher tells me, that my Future is ready, when i am not even starting the Future... How can that be?



ResourceCreator::ResourceCreator(boost::shared_ptr<Resource> _Resource, boost::function<void (ipf_viewer::RESOURCE_CREATION_STATUS)> _FuncPointer) :
m_CreationStatus(SCHEDULED),
m_Resource(_Resource)
{
m_Listener.push_back(_FuncPointer);
QObject::connect(&m_FutureWatcher, SIGNAL(finished()), &m_SignalMapper, SLOT(map()));
m_SignalMapper.setMapping(&m_FutureWatcher, this);
QObject::connect(&m_SignalMapper, SIGNAL(mapped(QObject*)), ResourceManager::getInstance(), SLOT(handleFinished(QObject*)));

//m_FutureResource = QtConcurrent::run(*m_Resource, &Resource::_create, this);
m_FutureWatcher.setFuture(m_FutureResource);
};

So my FutureWatcher tells me, that he is ready, but i dont use run() at all! Why does it happen?
Very Interesting: I just have that problem of finished() executed and my own "handleFinished()" Slot when i am copying a boost::shared_ptr<ResourceCreator> like there:



boost::shared_ptr<ResourceCreator> RC(new ResourceCreator(theResource, _FuncPointerRes));
ResourceManagerData<T>::m_ScheduledCreators[_Filename] = RC;

Here is my ResourceCreator class:


enum RESOURCE_CREATION_STATUS { SCHEDULED, FINISHED, CANCELLED };
class ResourceCreator : public QObject
{
Q_OBJECT
public:
ResourceCreator(boost::shared_ptr<Resource>, boost::function<void (ipf_viewer::RESOURCE_CREATION_STATUS)>);
~ResourceCreator();
void run();

boost::shared_ptr<Resource> m_Resource;
QFuture< boost::shared_ptr<Resource> > m_FutureResource;
QFutureWatcher< void > m_FutureWatcher;
QSignalMapper m_SignalMapper;
RESOURCE_CREATION_STATUS m_CreationStatus;
std::vector< boost::function<void (ipf_viewer::RESOURCE_CREATION_STATUS)> > m_Listener;

private:
ResourceCreator(const ResourceCreator&);
};

btw: It works, when i use the run() method! But it fails, through calling finished() immediately, when i dont use run()!