'QFutureWatcher' does not name a type
-
wrote on 8 Apr 2016, 22:04 last edited by nulluse 4 Aug 2016, 22:31
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?
-
wrote on 9 Apr 2016, 00:10 last edited by
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 -
wrote on 9 Apr 2016, 01:54 last edited by
Great, but what's the solution? Moving the includes into the a.h file?
-
@nulluse said:
Hi
I think you might need
#include <QFutureWatcher>
in the .h file -
wrote on 9 Apr 2016, 17:45 last edited by
Can you clarify if I need to move
#include <QFutureWatcher>
from .cpp.cc file into .h file, or include it in both? -
Can you clarify if I need to move
#include <QFutureWatcher>
from .cpp.cc file into .h file, or include it in both?Lifetime Qt Championwrote on 9 Apr 2016, 17:53 last edited by mrjj 4 Sept 2016, 17:53
6/6