Signal and slots
-
Hi,
I have been using SIGNAL-SLOT for a long time.But I have one connection which doesn’t want work.
I emitted the signal, but nothing happened.
My code:
@connect(stations, SIGNAL(send(int,int,int)), cServer, SLOT(writeToCiensAll(int, int ,int) ));@
cServer has its own thread using moveToThread(&Thread function);
According to the “connect” I have two objects:
@
//stations object header
signals:
void send(int, int ,int);@@
//cServer object:
//in header:
public slots:
void writeToCiensAll(int, int, int );@@
//in cpp:
void Server::writeToCiensAll(int station, int state, int size){
qDebug() << "message is sent";
//code here
}@ -
What does the connect call return? Do you get any output on the console/debugging stream?
-
And the emit
@ emit send(12,1,2);@ -
the return value of connect(…) is true.
I also used Debug, but I didn’t know what I should have done. Because there were not any value to check.
I went step by step.
When I emit the signal this function is used only:
(according to debug step by step function)
@void Stations::send(int _t1, int _t2, int _t3)
{
void _a[] = { 0, const_cast<void>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)), const_cast<void*>(reinterpret_cast<const void*>(&_t3)) };
QMetaObject::activate(this, &staticMetaObject, 1, _a);
}
@ -
Are you sure that you're not somehow re-creating the cServer instance or something like that after the connect call?
-
Does the server thread have a spinning event loop (that is did you call start() or at least exec() if you have reimplemented run())?
You won't be able to receive signals if you haven't.
-
[quote author="Lukas Geyer" date="1360845486"]Does the server thread have a spinning event loop (that is did you call start() or at least exec() if you have reimplemented run())?
You won't be able to receive signals if you haven't.[/quote]
Excellent point! cServer does need a running eventloop of course...
-
cServer is a „special class”.
The new thread was made as a mentioned above. But I had problem with clients. I used the old c style to make new thread as a function. (pthread). But this is a class and the function is a member function.
I find a solution for this problem. I used a static member function to call the „new thread function.”
Can be any connection between this solution and the signal?The server is waiting for client.
connect( … ) is the last line in the constructor of the class. I mean the class that is used to store the above objects.
-
I have solved this problem using function pointer. It is not the best solution but it works finally.