Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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.

    #include <pthread>
    #include <stdlib>
    #include <iostream>
    #include <fstream>
    using namespace std;
    #include <sigc++-2.0/sigc++/signal.h>
    class MyClass
            virtual ~MyClass();
            sigc::signal<void,int> MySignal1;
            sigc::signal<void,int> MySignal2;
            void WaitForSomething();  //reads certain files and triggers events
    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.

    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.

  2. #2
    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.

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Montgomery, AL

    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

  4. $spacer_open
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts