Re: [gtkmm] compilation error due to a signal connect
- From: Roger Leigh <roger whinlatter uklinux net>
- To: cedric <cedric probesys com>
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] compilation error due to a signal connect
- Date: Tue, 13 Apr 2004 18:40:14 +0100
cedric <cedric probesys com> writes:
> Roger Leigh a écrit :
>
>>cedric <cedric probesys com> writes:
>>
>>
>>
>>>hi!
>>>i m a newbie on gtkmm and i have a little (BIG ;-/ ) problem:
>>>
>>>i ve made a class "test". in the constructor, i create a
>>>Gtk::Menu::MenuElem MenuName, and i want to connect it with a function
>>>"print". it works only and only if this "print" function is declared
>>>as static, because if i declare it virtual (or even without virtual)
>>>and not static, i have a compilation error :
>>
>>> SigC::slot(&test::print) ); //here is the problem!
>>
>>A pointer to a class member function requires a reference to the class
>>as well as the method:
>>
>> SigC::slot(*this, &test::print) );
> i ve just forgotten to put it in my mail, but it was in my source!
>
> because if i declare "print" as "static void print();" and if i put also
>
> "...SigC::slot(&test::print) );", it works ! and i forgot to reput "*this"!
> sorry for my mistake! but the problem still remains :'(
If print() is static, then you can use
SigC::slot(&test::print)
because there's no this pointer (it's not a class instance, i.e. an
object). It's equivalent to creating a slot from a function. If you
remove the static keyword, and try
SigC::slot(*this, &test::print)
you should find it works.
If it doesn't work, post a short compilable example that exhibits the
problem. The code you posted isn't meaningful on its own.
I suggest you have a read of the libsigc++ documentation. It explains
how all the signal and slot stuff works, with simple examples. You
can get the signalling concepts working before touching gtkmm.
The gtkmm book also has examples of menus.
--
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]