Re: [sigc] example1



Hi:
Please help me with this, I also have problems to compile some simple examples that I find in a libsigc++ rpm paquage, I try to compile with this command:

g++ signals.cc -o signals `pkg-config --cflags --libs sigc++-2.0`

the simple "hello_world.cc" work fine, but I try to compile a second example (at bottom of this message) I can't asociate object method, only funtion pointers (I comment the stuff that don't work to try to compile the rest of the example): // I don't know the correct libsigc++ include section, I use fedora 5 I try different combinations
#include <iostream>
#include <string>
// (1) Include the signal system in headers file.
//#include <sigc++/signal_system.h>
#include <sigc++/sigc++.h>
#include <sigc++/slot.h>
//#include <sigc++/functors/slot.h>
//#include <sigc++/object.h>
#include <sigc++/object_slot.h>
using namespace SigC;
using namespace std;

// Some procedures to connect to.
int foo1(int i) { cout<<"f("<<i<<");"<<endl;
       return 1;}
int foo2(int i) { cout<<"sig2::f("<<i<<");"<<endl; return 1;}

void foo1v(int i)
{    cout<<"fv("<<i<<");"<<endl;}
void foo2v(int i)
{    cout<<"sig2::fv("<<i<<");"<<endl;}

// (3) Objects which are to be connected must be derived from SigC::Object.
struct A : public Object
{
//public:
   A()     {    }
int foo(int i) { cout<<"A::f("<<i<<");"<<endl; return 1; }
    void foov(int i)
   {        cout<<"A::fv("<<i<<");"<<endl;    }
};

int main()
{
   A a;
   // (4) Signals can be declared anywhere, including as class members
   // Their size is about that of 2 pointers.
   // Signals contain their callback signature as template parameters.
   // The number following it is the number of parameters, and the
   // first argument is the return type.
// // So to declare a signal called like int foo(int) would be
   //    Signal1< int, int> foo;

   // Lets declare a few signals.
   Signal1<int,int> sig1;    // int sig1(int);
   Signal1<int,int> sig2;    // int sig2(int);

   // The return type is allowed to be void.
   Signal1<void,int> sig1v;  // void sig(int);
   Signal1<void,int> sig2v;  // void sig2(int);

   // (5) After the signals are declared you can establish
   // connections between them and functions and methods.
   cout << ">> Connect to signals "<< endl;

   // Connect to function foo.
   sig1.connect(slot(foo1));

   // Connect to method foo of object a.
   sig1.connect(slot(a,&A::foo)); //OJO DESCOMENTADA NO COMPILA !!!

   // Connect to signal 1 to signal 2.  Thus all things in signal2
   // are also called.
   //sig1.connect(sig2.slot()); DON'T WORK !!!

   // We can do the same for the void signals.
   sig1v.connect(slot(foo1v));
   //sig1v.connect(slot(a,&A::foov)); DON'T WORK !!!
   sig1v.connect(sig2v.slot());

   sig2.connect(slot(foo2));
   sig2v.connect(slot(foo2v));

   // (6) After connection the signals can be "emitted".
   // This calls all the callbacks stored within the signal.
   // (Emits are generally called reverse of the order connected,
   // however this is implementation specific.)
   cout << ">> Emit signals "<< endl;

   // Explicitly calling the emits.
   sig1.emit(1);
   //sig1v.emit(2);

   // Or alternatively they can be called as a function object
   // with operator()
   sig1(1);
   //sig1v(2);
   return 0;
}

Do you have some working example with compilation instructions?

In advance, thank you very much.

Murray Cumming wrote:
On Thu, 2007-10-18 at 22:42 +0100, grassidonato2 tin it wrote:
I tried to compile "simple example" in the tutorial using the pkgconfig command and the file provided for it. As under cygwin as under kubuntu, it gives me the same problem with compiling. Thoroughly the installation of the library(libsigc++2.0) has comen out without any problems, and also the tests has been all passed. How do I can make a simple compilation as for the hello_world example without using that big makefile as in the example directory?
Many Thanks.

How are you trying to compile it, and what error are you seeing?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]