Results 1 to 3 of 3

Thread: parent/child callback

  1. #1
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default parent/child callback

    Although I can put Qt on a client, I can't put it on a server because it is running VxWorks OS (not supported by Qt).

    So I have to find a way to have a child send a signal to a parent function without the signal/slot paradigm.

    I'm trying to use callbacks.

    I can have a member variable in the child class that points to a function, but when I try to assign it to a parent function in a parent function it gives me trouble.

    I declared the callback in the child class as:

    Qt Code:
    1. void (*callback)(void)
    To copy to clipboard, switch view to plain text mode 

    And I try to set it in the parent class:

    Qt Code:
    1. child->callback = (void*)handleSignal;
    To copy to clipboard, switch view to plain text mode 

    It says:

    error: invalid use of member (did you forget the '&' ?)
    Do I just have the syntax wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: parent/child callback

    Sheesh, I can't even get a parent callback to point to a parent method.

    Here are some of the responses:

    Qt Code:
    1. callback = blankfunc; // error: argument of type ‘void (HadronServer::)()’ does not match ‘void (*)()’
    2. callback = (void*)blankfunc; // error: invalid use of member (did you forget the ‘&’ ?)
    3. callback = (void*)blankfunc(); // error: void value not ignored as it ought to be
    4. callback = (void*)&blankfunc(); // error: invalid lvalue in unary ‘&’
    5. callback = (void *)test; // error: invalid conversion from ‘void*’ to ‘void (*)()’
    6.  
    7. callback = &test; // works, but test is not a member function
    8. callback = &blankfunc; // error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HadronServer::blankfunc’
    9. callback = &HadronServer::blankfunc; // error: cannot convert ‘void (HadronServer::*)()’ to ‘void (*)()’ in assignment
    10. callback = &((void*)blankfunc); // error: invalid use of member (did you forget the ‘&’ ?)
    11. callback = (void *)(&blankfunc); // error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&HadronServer::blankfunc’
    12. callback = (void *)(&HadronServer::blankfunc); // error: converting from ‘void (HadronServer::*)()’ to ‘void*’
    To copy to clipboard, switch view to plain text mode 

    So it only works when I point it at a non-member function.

  3. #3
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: parent/child callback

    Ugh. It looks like this is not possible because it isn't a static function.

    This website tipped me off:

    http://www.codeguru.com/cpp/cpp/cpp_...cle.php/c10557

    The whole reason I wanted a callback was to pass info to a parent function, but obviously I can't do that if it's a static function.

Similar Threads

  1. timer callback greater than 2 power 31
    By sriky27 in forum Qt Programming
    Replies: 4
    Last Post: 18th March 2009, 10:57
  2. Non-Gui thread Callback API and Qt - how
    By The Storm in forum Qt Programming
    Replies: 9
    Last Post: 3rd November 2008, 19:24
  3. structs, pointer, static callback function
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 20th June 2008, 12:53
  4. Callback in QT
    By gajendersingh in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 10:52
  5. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.