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. QObject::connect simply "rejects" my object at compile-time(!)
Forum Updated to NodeBB v4.3 + New Features

QObject::connect simply "rejects" my object at compile-time(!)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.5k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    C is a QObject derived class, I can use it successfully.

    I get a compilation error on the "connect". If i'd change "this->controller", to "this", on the target, it will work fine. Something about the this->controller as the recipient causes this not to compile. I realize it must be something stupid, but the cause evades me.

    @MyClass::MyClass(C * controller)
    : QThread(NULL)
    {
    this->controller = controller;
    QObject::connect(this, SIGNAL(OnResponse(ResponseClass*)), this->controller, SLOT(OnResponse(ResponseClass*))); // <---- "Compiler error: " error: no matching function for call to...."
    }@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Hard to debug without the actual compiler error - you left out the real interesting part.

      Some guesses:

      • class C lacks the Q_OBJECT macro
      • this->controller is not a pointer

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ronM71
        wrote on last edited by
        #3

        Checked again. Q_OBJECT exists in C. this->controller is a pointer. One thing I did notice though. The class of the C had only a forward declaration as I couldn't use its *.h file due to circular reference. Could this be at play here?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Yes, this is the reason. The connect method takes a QObject pointer as the third argument. As long as the header file of class C is not included, the compiler does not know about the fact that you inherited from QObject and thus treads the pointer like a void pointer (at least kind-of in the sense of the error message, the compiler gurus may add some additional insight).

          Be aware, that without including C's header file in MyClass implementation, you would never be able to call methods on the this->controller pointer.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

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