Results 1 to 4 of 4
Hi all,
I'm currently working on a C++ console application has a few classes and I wanted to enable certain classes to raise events back to event handlers in main.cpp. ...
- 12-16-2009 #1Just Joined!
- Join Date
- Sep 2003
- Posts
- 22
Using libsigc++ for events in C++
Hi all,
I'm currently working on a C++ console application has a few classes and I wanted to enable certain classes to raise events back to event handlers in main.cpp. I came across libsigc++-2.0 but am having problems actually using it.
It installs just fine on my Ubuntu 9.04 box (both the runtime and dev packages) but I'm not sure what to actually #include in my source code. I tried following the tutorial on the libsigc++ site (Chapter*2.*Connecting your code to signals) but it doesn't give any information on what libsigc++ headers I need.
I think I narrowed it down to #include <sigc++-2.0/sigc++/signals.h>, but I am getting hundreds of compiler errors similar to " '_A_a1_' was not declared in this scope" referencing signal.h.
Following is some code for my class header. I haven't put anything into the implementation file yet, or main.cpp.
My intent was in WaitForSomething() to execute MySignal1.emit() (or MySignal2.emit()), which would be connected to OnMySignalX functions in main.cpp, but that part hasn't been written yet.Code:#include <pthread> #include <stdlib> #include <iostream> #include <fstream> using namespace std; #include <sigc++-2.0/sigc++/signal.h> class MyClass { public: MyClass(); virtual ~MyClass(); sigc::signal<void,int> MySignal1; sigc::signal<void,int> MySignal2; void WaitForSomething(); //reads certain files and triggers events };
On a side note: For some reason, if I remove 'int' from the MySignal1 or MySignal2 declaration (e.g., sigc::signal<void> MySignal1;, the compiler tells me I have an invalid entry for argument 2. I thought signal was supposed to be a wrapper so only the first argument (the template's return type) is required.
- 12-21-2009 #2Just Joined!
- Join Date
- Sep 2003
- Posts
- 22
Anyone? I've tried several approaches here including using versions 1.2 and 2.0 of libsigc++. I can manage to get it to the point where my code compiles, but the signal.h header of libsigc++ generates 750+ compiler errors.
- 09-28-2010 #3Just Joined!
- Join Date
- Sep 2010
- Location
- Montgomery, AL
- Posts
- 27
I know this is old but.
I compiled using
#include <sigc++/sigc++.h>
in my header file. With
`pkg-config sigc++-2.0 --cflags` with the compiler and
`pkg-config sigc++-2.0 --libs` with the linker
- 09-28-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Sorry, but I haven't used C++ signal template classes so I can't really help you in this regard. However, usually for C++ event handling one should use C++ exceptions, try/throw/catch. You might want to use sigc::signal<RT,AT> classes to catch external signals (SIGUSR1, SIGKILL, etc), and then throw the appropriate exception to be caught in main().
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote