[SOLVED] Help using SLOTs
I cannot for the life of me, get my slot to be connected/recognized. Any help would be appreciated.
The following class just connects and polls a simple telnet server running on port 8090. The connection and reading work fine. (I was originally using UDP,hence the weird file/class names).
class XpUDP : public QObject
XpUDP(char * host = "localhost", int port = 8090);
QTcpSocket * getTelnet();
QTcpSocket * telnet;
char * myhost;
#endif // XPUDP_H
XpUDP::XpUDP(char * host, int port)
myhost = host;
myport = port;
telnet = new QTcpSocket;
isConnected = connectTelnet();
QTcpSocket * XpUDP::getTelnet() /* Just have this for testing purposes */
void XpUDP::readPort() // This SLOT not being recognized
int read_ret = 0;
memset(buf, 0, 512);
read_ret = telnet->read(buf, 512); //printf("recived[%i] '%s'\n", read_ret, buf); std::cout << buf; memset(buf, 0, 512);
if (telnet->waitForConnected(5000) == false)
this, SLOT(readPort())); /* I get QObject::connect: No such slot QObject::readPort() */
During runtime, if a connection is made I get this message in the console: QObject::connect: No such slot QObject::readPort(). Any help getting my slot reacting to the signal would be appreciated, or if events would be the way to go.
I have Qt 4.8.2, using Qt Creator 2.4.1, qmake 2.01a, g++ 4.7.0, on a Linux Fedora 17 x86_64 system.
FYI if it helps, I am making a moving map (MarbleMap) and instrument cluster for a flight sim.
You forgot to include the Q_OBJECT macro in your class declaration.
Be sure and add the Q_OBJECT macro when you define your class.
[Edit: Andre beat me to it.]
Awesome, works now.
After I added Q_OBJECT, did a make clean and rebuilt; I got an undefined reference to vtable for xxx. After running qmake -r all is good.
Be sure and edit your initial post to add [Solved] to the title. Thanks!