PDA

View Full Version : QTimer dificultty



jjbabu
6th November 2008, 09:07
Hi,
I have a function like below


void Class Name::stop()
{
QByteArray p("A008@");
port->open(QIODevice::ReadWrite);
port->write(p);
port->close();
}

when i cal the function directly(like this stop();),The data is going to port and that will be collected at the other end.
But the problem is when i call like below,


QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(stop()));
timer->start(1000);

nothing is going from the port,am not able to collect the data at other end.
What is the problem with that above code?
can anybody help me on this issue

thanks a lot.

muellerp
6th November 2008, 10:45
Is the timer really executed?
Do you have an eventloop?

pastor
6th November 2008, 18:00
Please modify your code like that:


void Class Name::stop()
{
QByteArray p("A008@");
port->open(QIODevice::ReadWrite);
qDebug() << "Port is opened: " << port->isOpen();
qDebug() << "Written " << port->write(p); << " bytes."
port->close();
}

and show us output.

lyuts
8th November 2008, 18:38
I would guess that stop() is not declared as a slot.