Qt-interest Archive, March 2007
simple(?) signal / slot problem
Message 1 in thread
Hello list,
While making my first real foray into the world of QT programming, I've
hit a brick wall when trying to set up a simple signal / slot
connection. After re-reading all the docs and exhausting google on the
subject, I thought I'd post here..
I want my 'OnClientConnect' method to be called every time a QTCPServer
received a new connection. However, I get the error message
"Object::connect: No such slot ALServer::OnClientConnect"
I have made sure that Q_OBJECT macro is in my ALServer class definition.
Moc is run, and the output is compiled and linked into my application.
My class definition is simplicity itself:
<code>
#include <Qt/QObject.h>
#include <Qt/QTcpServer.h>
// auto loader server class. stuff happens here.
class ALServer : public QObject
{
Q_OBJECT
protected:
// signal handlers:
void OnClientConnect();
public:
ALServer();
private:
QTcpServer m_tcpServer;
};
</code>
And the implementation is also pretty simple:
<code>
// called when a client tries to connect to us:
void ALServer::OnClientConnect()
{
QTcpSocket *newSock = m_tcpServer.nextPendingConnection();
newSock->write("Goodbye", 100);
newSock->close();
}
ALServer::ALServer()
{
// do setup stuff for the server here.
m_tcpServer.listen(QHostAddress::Any, 666);
connect(&m_tcpServer, SIGNAL(newConnection()), this,
SLOT(OnClientConnect()));
}
</code>
I've tried all sorts of variations on the current connect() call.. I've
tried putting in type names (both void in this case), adding and
removing parenthesis... I hope someone here can point out what's going
on!
Thanks in advance!
--
[ signature omitted ]
Message 2 in thread
Hi Thomas,
Might be I'm missing something, but I can not see where you have stated that
onClientConnect() is a slot. Should you not do something along the lines of
public slots:
void onClientConnect();
?
--
[ signature omitted ]
Message 3 in thread
> "Object::connect: No such slot ALServer::OnClientConnect"
>
> protected:
> // signal handlers:
> void OnClientConnect();
Hi Thomas!
Make this a "protected slots:"...
HTH, Martin
--
[ signature omitted ]
Message 4 in thread
On Thursday 29 March 2007, Thomas Richards wrote:
> Hello list,
>
>
> While making my first real foray into the world of QT programming, I've
> hit a brick wall when trying to set up a simple signal / slot
> connection. After re-reading all the docs and exhausting google on the
> subject, I thought I'd post here..
>
>
> I want my 'OnClientConnect' method to be called every time a QTCPServer
> received a new connection. However, I get the error message
>
>
> "Object::connect: No such slot ALServer::OnClientConnect"
>
> I have made sure that Q_OBJECT macro is in my ALServer class definition.
> Moc is run, and the output is compiled and linked into my application.
>
> My class definition is simplicity itself:
>
> <code>
> #include <Qt/QObject.h>
> #include <Qt/QTcpServer.h>
>
>
> // auto loader server class. stuff happens here.
> class ALServer : public QObject
> {
> Q_OBJECT
> protected:
> // signal handlers:
> void OnClientConnect();
>
> public:
> ALServer();
>
>
> private:
> QTcpServer m_tcpServer;
> };
> </code>
>
>
> And the implementation is also pretty simple:
>
> <code>
> // called when a client tries to connect to us:
> void ALServer::OnClientConnect()
> {
> QTcpSocket *newSock = m_tcpServer.nextPendingConnection();
> newSock->write("Goodbye", 100);
> newSock->close();
>
> }
>
> ALServer::ALServer()
> {
> // do setup stuff for the server here.
> m_tcpServer.listen(QHostAddress::Any, 666);
>
> connect(&m_tcpServer, SIGNAL(newConnection()), this,
> SLOT(OnClientConnect()));
> }
> </code>
>
>
> I've tried all sorts of variations on the current connect() call.. I've
> tried putting in type names (both void in this case), adding and
> removing parenthesis... I hope someone here can point out what's going
> on!
>
>
>
> Thanks in advance!
You have to assign your OnClientConnect as a slot.
Instead of :
protected:
// signal handlers:
void OnClientConnect();
You have to do something like:
private slots:
void OnClientConnect();
--
[ signature omitted ]
Message 5 in thread
Try to write
protected slots:
void OnClientConnect();
instead of
protected:
void OnClientConnect();
so moc is able to create the appropriate code for the slot.
Roland
-----Ursprüngliche Nachricht-----
Von: Thomas Richards [mailto:thomas.richards@xxxxxxxxx]
Gesendet: Donnerstag, 29. März 2007 11:29
An: qt-interest@xxxxxxxxxxxxx
Betreff: simple(?) signal / slot problem
Hello list,
While making my first real foray into the world of QT programming, I've
hit a brick wall when trying to set up a simple signal / slot
connection. After re-reading all the docs and exhausting google on the
subject, I thought I'd post here..
I want my 'OnClientConnect' method to be called every time a QTCPServer
received a new connection. However, I get the error message
"Object::connect: No such slot ALServer::OnClientConnect"
I have made sure that Q_OBJECT macro is in my ALServer class definition.
Moc is run, and the output is compiled and linked into my application.
My class definition is simplicity itself:
<code>
#include <Qt/QObject.h>
#include <Qt/QTcpServer.h>
// auto loader server class. stuff happens here.
class ALServer : public QObject
{
Q_OBJECT
protected:
// signal handlers:
void OnClientConnect();
public:
ALServer();
private:
QTcpServer m_tcpServer;
};
</code>
And the implementation is also pretty simple:
<code>
// called when a client tries to connect to us:
void ALServer::OnClientConnect()
{
QTcpSocket *newSock = m_tcpServer.nextPendingConnection();
newSock->write("Goodbye", 100);
newSock->close();
}
ALServer::ALServer()
{
// do setup stuff for the server here.
m_tcpServer.listen(QHostAddress::Any, 666);
connect(&m_tcpServer, SIGNAL(newConnection()), this,
SLOT(OnClientConnect()));
}
</code>
I've tried all sorts of variations on the current connect() call.. I've
tried putting in type names (both void in this case), adding and
removing parenthesis... I hope someone here can point out what's going
on!
Thanks in advance!
--
[ signature omitted ]
Message 6 in thread
On 3/29/07, Thomas Richards <thomas.richards@xxxxxxxxx> wrote:
> While making my first real foray into the world of QT programming, I've
> hit a brick wall when trying to set up a simple signal / slot
> connection. After re-reading all the docs and exhausting google on the
> subject, I thought I'd post here..
change:
> protected:
> // signal handlers:
> void OnClientConnect();
to
protected slots:
void OnClientConnect();
--
[ signature omitted ]
Message 7 in thread
Ahh, thanks a lot for your help.
It's really easy to miss that in the Signals & Slots documentation..
Perhaps it should be written in BIG letters ;)
Cheers.
--
[ signature omitted ]
BEGIN:VCARD
VERSION:2.1
N:Richards;Thomas
FN:Thomas Richards
EMAIL;PREF;INTERNET:thomas.richards@xxxxxxxxx
REV:20070226T164514Z
END:VCARD