June 2, 2011

Eonz Eonz
Lab Rat
22 posts

Implementing pointers to methods

 

Hi, I would like to write a function that pops up a dialog to allow the user to edit a certain variable. I would like the dialog to be able to make a call back to the original class (or any specified class) to notify that the value changed.

So now I have to define something like this:

  1. typedef void (QObject::*NotifyEvent)();

And pass two extra parameters to my function: one for the method and one for the class. This seems a bit cumbersome, plus I’m now worried about inheritance problems, because what if the specified class is not simply a QObject?

So I was wondering perhaps there are some standard Qt way of doing this sorta thing? Perhaps some defined types so that I don’t have to reinvent?

Any help would be appreciated!

2 replies

June 2, 2011

Franzk Franzk
Lab Rat
830 posts

http://doc.trolltech.com/latest/signalsandslots.html

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

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

June 3, 2011

Eonz Eonz
Lab Rat
22 posts

Thanks Franzk

I wasn’t certain if signals & slots could be used in this way but it turns out it works beautifully.

Somehow slots can be communicated as regular character strings and I don’t know how it REALLY works but they can passed on as a parameter this way to be connected to elsewhere and that’s all I really care about :)

I’m really starting to like Qt :D

 
  ‹‹ [SOLVED] Double to Int      How to handle dynamic memory allocation failure ››

You must log in to post a reply. Not a member yet? Register here!