Results 1 to 4 of 4

Thread: Slot not being called when QFutureWatcher is finished

  1. #1
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. private:
    2. QFutureWatcher<GDALDataset *> *watcher;
    3. QFuture<GDALDataset *> future;
    4. public slots:
    5. void copyComplete(QFuture<GDALDataset *>);
    To copy to clipboard, switch view to plain text mode 

    And in the function where I want to use these, I have the following:


    Qt Code:
    1. watcher = new QFutureWatcher<GDALDataset *>();
    2. connect(watcher,SIGNAL(finished()),this,SLOT(copyComplete(future)));
    3.  
    4.  
    5. future = QtConcurrent::run(boost::bind<GDALDataset *>(&GDALDriver::CreateCopy,poNITFDriver, pszDstFilename, poDataset, FALSE, papszOptions, pfnProgress, progMessage));
    6. watcher->setFuture(future);
    To copy to clipboard, switch view to plain text mode 

    and my slot:

    Qt Code:
    1. void ViewerMain::copyComplete(QFuture<GDALDataset *>f)
    2. {
    3. qDebug("Copy complete fired!");
    4. }
    To copy to clipboard, switch view to plain text mode 


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

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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:
    Qt Code:
    1. connect(watcher,SIGNAL(finished()),this,SLOT(copyComplete()));
    2. // and change the slot:
    3. void ViewerMain::copyComplete()
    4. {
    5. qDebug("Copy complete fired!");
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by stampede; 12th July 2011 at 21:04. Reason: removed not needed info

  3. #3
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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() :
    Qt Code:
    1. void ViewerMain::copyComplete()
    2. {
    3. qDebug("Copy complete fired!");
    4. QFutureWatcher<GDALDataset *> * watcher = qobject_cast< QFutureWatcher<GDALDataset *>* >(sender());
    5. if( watcher ){
    6. QFuture<GDALDataset *> future = watcher->future();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 19:27
  2. Replies: 3
    Last Post: 7th April 2011, 12:09
  3. QProcess finished slot not firing
    By doggrant in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2010, 14:09
  4. Slot gets called twice
    By greatgatsby in forum Newbie
    Replies: 7
    Last Post: 20th August 2009, 16:11
  5. SLOT not being called
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2007, 12:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.