Results 1 to 8 of 8

Thread: How to pass a member funtion to another object using funtion pointer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to pass a member funtion to another object using funtion pointer

    Thanks for your suggestions.

    this is where I call the constructor of popup and I get the above error message.

    void Widget:n_pushButton_clicked()
    {
    popup popDia(this,putString);
    popDia.exec();
    }

    Just trying to implement a call back in c++.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to pass a member funtion to another object using funtion pointer

    What is the definition of 'Widget' ? You seem to be referring to it as a base case, but you don't seem to inherit from it?

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to pass a member funtion to another object using funtion pointer

    I would recommend using functors, also known as function objects, in place of the cumbersome function pointer syntax. They are perfect for use as callbacks.

    Of course, signals and slots do away with much of the need for callback functions; you can simply connect the objects that need to communicate.

  4. #4
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to pass a member funtion to another object using funtion pointer

    You still haven't provided the definition of Widget, so its hard to help. From the error message I would guess, that you have two putString functions in Widget, and hence the compiler is unable to resolve which one to take.
    As an alternative approach, apart from a functor (function object) you could also use the listener concept (i.e. observer pattern).

Similar Threads

  1. Replies: 11
    Last Post: 14th March 2010, 22:00
  2. Replies: 14
    Last Post: 1st December 2009, 20:45
  3. Replies: 2
    Last Post: 7th July 2009, 17:44
  4. ActiveQt: How to pass image to ActiveX object?
    By AndreasSchlempp in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2009, 12:44
  5. static Object Vs Pointer
    By rajeshs in forum General Programming
    Replies: 4
    Last Post: 11th June 2008, 07:41

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.