SOLVED - Qt slot problem - don't forget the Q_OBJECT macro!!!!!!
-
Hi,
I am currently writing a small project, in it I have an object (mainWindow.cpp) that has several slots that are triggered by time events. They all work fine. In my main class I have a member (serialPort.cpp) which is a class that controls a serial port, I am trying to set up a signal/slot that does a one shot. This will be used so that I can timeout if I don;t get any serial back.So a function in mainWindow.cpp ceates an instance of a serialPort.cpp at some time mainWindow.cpp starts the process to send serial data, I would like a one shot to 'go-off' at some time in the future if I don't have a response. When I try the following code I get a warning in my output dialog that the slot can't be found.
in the header of serialPort.cpp
private:QTimer *ATresponseTimer;
private slots:
void ATcommandResponseTimeout(void);
In the constructor of serialPort.cpp
ATresponseTimer = new QTimer;
connect ( ATresponseTimer, SIGNAL ( timeout() ), this, SLOT ( ATcommandResponseTimeout () ) );
ATresponseTimer->setSingleShot(true);
ATresponseTimer->stop();
also is serialPort.cpp
void serialPort::ATcommandResponseTimeout(void)
{
// we sent an AT command but never got a response in time,
qDebug() << "Modem response timed out";
}The error I get is
Object::connect: No such slot QMainWindow::ATcommandResponseTimeout():serialPort in serialPort.cpp:10I am sure I am forgetting to do something simple, any pointers ;-) would be great
Phil
-
I would check the name of the slot (it is likely a typo in the name 'ATcommandResponseTimeout').
You could do it another way possibly.
You could use a timer (maybe one of your existing ones) to check if any data was received between events. All you need to do is set a variable every time you receive data and clear it on the timer event. If your variable is not set between events nothing was received. It might be simpler to implement.
-
Thanks Rondog, I went for a walk and a cup of coffee, when I got back I suddenly realised that I forgot to place Q_OBJECT in serialPort.h
It re-emphasises the idea of taking a break when the wheels start falling off!