Slot not being called when QFutureWatcher is finished
Hello,
I am trying to figure out why my watcher does not appear to call it's finished signal, and in turn, my slot is not being called.
in my header file, I have the following declared:
Code:
private:
QFutureWatcher<GDALDataset *> *watcher;
QFuture<GDALDataset *> future;
public slots:
void copyComplete(QFuture<GDALDataset *>);
And in the function where I want to use these, I have the following:
Code:
watcher = new QFutureWatcher<GDALDataset *>();
connect(watcher,SIGNAL(finished()),this,SLOT(copyComplete(future)));
future = QtConcurrent::run(boost::bind<GDALDataset *>(&GDALDriver::CreateCopy,poNITFDriver, pszDstFilename, poDataset, FALSE, papszOptions, pfnProgress, progMessage));
watcher->setFuture(future);
and my slot:
Code:
void ViewerMain::copyComplete(QFuture<GDALDataset *>f)
{
qDebug("Copy complete fired!");
}
That last qDebug statement never gets called. What am I doing wrong?
Re: Slot not being called when QFutureWatcher is finished
Signal and slot signature does not match, you should get a warning message about connect statement - you cannot connect a signal with no parameters to a slot expecting a parameter, because what should be the parameter value inside the slot when signal is delivered ?
This should work:
Code:
connect(watcher,SIGNAL(finished()),this,SLOT(copyComplete()));
// and change the slot:
void ViewerMain::copyComplete()
{
qDebug("Copy complete fired!");
}
Re: Slot not being called when QFutureWatcher is finished
Oh. I had noticed that when I called a signal with no parameters that it worked. Is it possible to re-work this so that the slot can accept a parameter? I was looking for a way to get the result of future in the copyComplete() slot. Right now, I have to have future as a class member variable
Re: Slot not being called when QFutureWatcher is finished
You need to respect the QFutureWatcher api, signal has no parameters, so it can be connected only to slots that takes no parameter.
If you want to get QFuture inside the slot, you can use QFutureWatcher::future() method. And in order to get QFutureWatcher, use qobject_cast on sender() :
Code:
void ViewerMain::copyComplete()
{
qDebug("Copy complete fired!");
QFutureWatcher<GDALDataset *> * watcher = qobject_cast< QFutureWatcher<GDALDataset *>* >(sender());
if( watcher ){
QFuture<GDALDataset *> future = watcher->future();
}
}