Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

'QFutureWatcher' does not name a type



  • When I moved declaration of a QFutureWatcher object from a member function (where it was a local variable) to the header (in order to use its finished() signal), it started throwing the error in subject.

    a.cpp.cc was:

    #include <QtCore>
    #include <QFutureWatcher>
    #include <QMessageBox>
    #include <QCoreApplication>
    #include <QtConcurrent>
    #include <QFileDialog>
    #include "a.h"
    
    a::fn() {
      auto lambda [x, y] (int& i) -> int {return 1;};
      QFutureWatcher<void> fw;
      fw.setFuture(QtConcurrent::map(vec, lambda));
    }
    

    a.cpp.cc became:

    #include <QtCore>
    #include <QFutureWatcher>
    #include <QMessageBox>
    #include <QCoreApplication>
    #include <QtConcurrent>
    #include <QFileDialog>
    #include "a.h"
    
    a::fn() {
      auto lambda [x, y] (int& i) -> int {return 1;};
      fw.setFuture(QtConcurrent::map(vec, lambda));
    }
    

    a.h became:

    class a : public QDialog {
        Q_OBJECT
    public:
        a();
        virtual ~a();
    private:
    	QVector<int> vec;
    	QRect rect;
    	QGraphicsScene *scene; // added the next line:
    	QFutureWatcher<void> fw; // -- error on this new line: 'QFutureWatcher' does not name a type
    };
    

    I thought that as a.cpp.cc included the Qt headers before including a.h, QFutureWatcher should have been declared on the line where the error is being raised. What am I missing?



  • Your a.h file is also used by moc without using your .cc file.
    moc produces a cpp-file containing the qobject-related things for your class. When this file is compiled qfuturewatcher is unknown.
    Gerd



  • Great, but what's the solution? Moving the includes into the a.h file?


  • Lifetime Qt Champion

    @nulluse said:
    Hi
    I think you might need
    #include <QFutureWatcher>
    in the .h file



  • Can you clarify if I need to move #include <QFutureWatcher> from .cpp.cc file into .h file, or include it in both?


  • Lifetime Qt Champion

    @nulluse
    hi
    you should only need in .h
    if cpp.cc file does include that .h


Log in to reply