Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 'QFutureWatcher' does not name a type
QtWS25 Last Chance

'QFutureWatcher' does not name a type

Scheduled Pinned Locked Moved Solved General and Desktop
qfuturewatcher
6 Posts 3 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nulluse
    wrote on 8 Apr 2016, 22:04 last edited by nulluse 4 Aug 2016, 22:31
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gerd
      wrote on 9 Apr 2016, 00:10 last edited by
      #2

      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

      1 Reply Last reply
      1
      • N Offline
        N Offline
        nulluse
        wrote on 9 Apr 2016, 01:54 last edited by
        #3

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 9 Apr 2016, 09:30 last edited by
          #4

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

          1 Reply Last reply
          2
          • N Offline
            N Offline
            nulluse
            wrote on 9 Apr 2016, 17:45 last edited by
            #5

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

            M 1 Reply Last reply 9 Apr 2016, 17:53
            0
            • N nulluse
              9 Apr 2016, 17:45

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 9 Apr 2016, 17:53 last edited by mrjj 4 Sept 2016, 17:53
              #6

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

              1 Reply Last reply
              1

              1/6

              8 Apr 2016, 22:04

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved