Hi,

I try to use QFuture/QFutureWatcher for my own project. So far I have this
simplified setting, in which Handler is living in the GUI thread:

class Worker : public QObject
{
  Q_OBJECT

  public slots:
    void doHeavyStuff(QFutureInterface<int> inter) {
      inter.reportResult(42);
      inter.reportFinished();
    }
};

class Handler : public QObject
{
  Q_OBJECT

  public:
    Handler(QObject *parent = 0) :
      QObject(parent),
      m_worker(new Worker)
    {
      m_worker->moveToThread(&m_thread);
      connect(&m_thread, &QThread::finished, m_worker,
&QObject::deleteLater);
      m_thread.start();
    }

    QFuture<int> meaningOfLife()
    {
      QFutureInterface<int> inter;
      inter.reportStarted();
      QMetaObject::invokeMethod(m_worker, "doHeavyStuff",
Qt::QueuedConnection, Q_ARG(QFutureInterface<int>, inter));
      return inter.future();
    }

  private:
    Worker *m_worker;
    QThread m_thread;
};

This works fine if I add "qRegisterMetaType<QFutureInterface<int>
>("QFutureInterface<int>");" somewhere. This, however, makes me nervous
because it feels like I have not to do this. It's a pure paranoid feeling...
Therefore:
  a) Is the approach above okay?
  b) Why QFutureInterface isn't registered already by Qt? Is it because one
can't register templated classes easily?

Thanks
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to