PDA

View Full Version : Signal defined in "a.h" can not emit in "b.cpp"



Shawn
21st May 2007, 14:55
I defined a siganl in "a.h" like this:
signals:
void Sgl(int);

when I want to emit it in "b.cpp"
A a;
emit a.Sgl(int);

error C2248: 'A::Sgl' : cannot access protected member declared in class 'A'

this is a very common problem if u want to emit signal in class while it is defined in another class. Any one can help me ?

high_flyer
21st May 2007, 14:59
this is a very common problem if u want to emit signal in class while it is defined in another class. Any one can help me ?
What do you mean?
could you post your code?

Shawn
21st May 2007, 15:15
What do you mean?
could you post your code?

"a.h":
signals:
void Sgl(int);

"b.cpp"
A a;
emit a.Sgl(int);

Is this clear ?:confused:

wysota
21st May 2007, 15:20
Create a public method in A that will emit the signal.


class A : public QObject {
Q_OBJECT
public:
A(QObject *parent=0) : QObject(parent){}
void emitSig(){ emit sig(); }
signals:
void sig();
};

BTW. You should avoid emitting signals on account of other objects behind their back. If you do that, it's likely that your design is incorrect.

Shawn
21st May 2007, 15:34
can i do it like this?
A a;
B b;
connect (&a, Sgl_a(),&b, Sgl_b());

I tried, but still:
error C3861: 'connect': identifier not found

I am totally confused

wysota
21st May 2007, 15:43
What is Sgl_a() ? Remember about SIGNAL() and SLOT() macros.

Shawn
21st May 2007, 15:53
What is Sgl_a() ? Remember about SIGNAL() and SLOT() macros.

of course i won't make that mistake
that is just an example

high_flyer
21st May 2007, 16:20
can i do it like this?
A a;
B b;
connect (&a, Sgl_a(),&b, Sgl_b());

I tried, but still:
error C3861: 'connect': identifier not found

of course i won't make that mistake
that is just an example
We can't know what you are thinking.
And we don't know which mistakes you might make or not - and judging from your post, you are not a very experienced Qt programmer, so you might be doing all kinds of mistakes you are not aware of (and neither are we, if we don't see the code).
And when dealing with a problem, anything can be a cause, so if you want us to be able to help you, should should deliver as accurate information as you can.
Why don't you just post the code?
(And I don't mean just a signal definition line - but your header and the implementation files that are in question).

Oh - and when posting code, please, use code tags.

jpn
21st May 2007, 16:54
error C3861: 'connect': identifier not found

QObject::connect() is a static method of QObject. Sounds like you try to connect outside a QObject, so try:


QObject::connect(...);

QObject header should already be included at least indirectly as both A and B are QObjects.

freeskydiver
21st May 2007, 16:55
I defined a siganl in "a.h" like this:
signals:
void Sgl(int);

when I want to emit it in "b.cpp"
A a;
emit a.Sgl(int);

error C2248: 'A::Sgl' : cannot access protected member declared in class 'A'

this is a very common problem if u want to emit signal in class while it is defined in another class. Any one can help me ?

When the signal is private then give your class a nice public function. Which emit your signal.