PDA

View Full Version : SLOT fires only on mouse move



kartun
4th February 2011, 14:33
I've this code ... stripped a bit


void testform::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_4 :
if (!demo_started)
{
this->buttons[0]->setPixmap(QPixmap::fromImage(images[1]));
this->listener = new PortListener(portName);

// So, connect to listener, and ... all happy :P
connect(this->listener,SIGNAL(packet_received(data_answer)),
this,SLOT(packet_received(data_answer)));

}
else
{
this->buttons[0]->setPixmap(QPixmap::fromImage(images[0]));
this->killTimer(demo_timer_id)
}
demo_started = !demo_started;
break;
...................................
default : QWidget::keyPressEvent(event);
}
}


and receiver SLOT:


void testform::packet_received(data_answer answer)
{
qDebug() << "pewpew all dead !";
redrawUI();
}


Problem is that this slot called only when I move mouse,press key etc. But signal itself emmited every 0.5 seconds (read data from com-port). Listener class is quite stable and works as intended.

high_flyer
4th February 2011, 14:53
Problem is that this slot called only when I move mouse,press key etc. But signal itself emmited every 0.5 seconds
Do you mean it only starts to be called after you have pressed a key (but then regularly gets called after that), or only when you press a key the slot is called?
Do you use diconnect() in your code anywhere, or delete the listener?

kartun
4th February 2011, 15:01
no, no disconnect() anywhere.
I checked with debugger, and even signal doesn't emitted unless I click on window, or press button. And yes, it's emitted only when i push/click.
Listener instance deleted in desctructor.

tryReceive() called in listener constructor first time, and then recalled with floating window.


void PortListener::tryReceive(){
if(this->port->bytesAvailable()>0){
timeout = qMax(100, timeout/2);
myRcvBuffer.clear();
myRcvBuffer.append(port->readAll());
qDebug() << "bytes read:" << myRcvBuffer.length();
qDebug() << "bytes:" << myRcvBuffer;
last_packet = Hemofenix_protocol::decode_packet(myRcvBuffer);
emit packet_received(last_packet);
} else {
timeout = qMin(1000, timeout*2);
}
QTimer::singleShot(timeout, this, SLOT(tryReceive()));
}


I put some qDebug() output there, but it do output only on user actions :(

high_flyer
4th February 2011, 15:13
But signal itself emmited every 0.5 seconds
Your posted code does not supports this assertion.
Your packet_received signal is only emitted when bayteAvailble()>0 is true however.
So it seems that for some reason bytesAvalable() returns 0 or less unless you press a key.
This sounds like a busy loop problem somewhere in your code.

kartun
7th February 2011, 06:55
Mystics ... I left code untouched for weekend, compiled today and it works like a charm. Really wired.
Thanks for replys.