PDA

View Full Version : Slot not being called when QFutureWatcher is finished



dcole
12th July 2011, 19:16
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:


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:



watcher = new QFutureWatcher<GDALDataset *>();
connect(watcher,SIGNAL(finished()),this,SLOT(copyC omplete(future)));


future = QtConcurrent::run(boost::bind<GDALDataset *>(&GDALDriver::CreateCopy,poNITFDriver, pszDstFilename, poDataset, FALSE, papszOptions, pfnProgress, progMessage));
watcher->setFuture(future);

and my slot:


void ViewerMain::copyComplete(QFuture<GDALDataset *>f)
{
qDebug("Copy complete fired!");
}


That last qDebug statement never gets called. What am I doing wrong?

stampede
12th July 2011, 20:03
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:


connect(watcher,SIGNAL(finished()),this,SLOT(copyC omplete()));
// and change the slot:
void ViewerMain::copyComplete()
{
qDebug("Copy complete fired!");
}

dcole
12th July 2011, 20:12
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

stampede
13th July 2011, 08:24
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() (http://doc.qt.nokia.com/latest/qfuturewatcher.html#future) method. And in order to get QFutureWatcher, use qobject_cast on sender() :


void ViewerMain::copyComplete()
{
qDebug("Copy complete fired!");
QFutureWatcher<GDALDataset *> * watcher = qobject_cast< QFutureWatcher<GDALDataset *>* >(sender());
if( watcher ){
QFuture<GDALDataset *> future = watcher->future();
}
}