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
Forum Updated to NodeBB v4.3 + New Features

'QFutureWatcher' does not name a type

Scheduled Pinned Locked Moved Solved General and Desktop
qfuturewatcher
6 Posts 3 Posters 2.2k Views 1 Watching
  • 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.
  • nulluseN Offline
    nulluseN Offline
    nulluse
    wrote on last edited by nulluse
    #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 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
      • nulluseN Offline
        nulluseN Offline
        nulluse
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          1 Reply Last reply
          2
          • nulluseN Offline
            nulluseN Offline
            nulluse
            wrote on 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?

            mrjjM 1 Reply Last reply
            0
            • nulluseN nulluse

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

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

              1 Reply Last reply
              1

              • Login

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