I tried doing my own implementation of these classes. Actually, I used the exact same code that is used in the simple network example in the Qt help files. Later on, I will have to change the newConnection function to do what I want it do, but for now, the only difference is that I want to us a different GUI, created with Qt designer, and I can't seem to get it work.
Instead of having this class in a cpp file:
class ServerInfo : public QVBox
{
Q_OBJECT
public:
ServerInfo()
{
SimpleServer *server = new SimpleServer( this );
"This is a small server example.\n"
"Connect with the client now."
);
lb->setAlignment( AlignHCenter );
infoText = new QTextView( this );
connect( server, SIGNAL(newConnect(ClientSocket*)),
SLOT(newConnect(ClientSocket*)) );
connect( quit, SIGNAL(clicked()), qApp,
SLOT(quit()) );
}
~ServerInfo()
{
}
private slots:
void newConnect( ClientSocket *s )
{
infoText->append( tr("New connection\n") );
connect( s, SIGNAL(logText(const QString&)),
infoText, SLOT(append(const QString&)) );
connect( s, SIGNAL(connectionClosed()),
SLOT(connectionClosed()) );
}
void connectionClosed()
{
infoText->append( tr("Client closed connection\n") );
}
private:
QTextView *infoText;
};
class ServerInfo : public QVBox
{
Q_OBJECT
public:
ServerInfo()
{
SimpleServer *server = new SimpleServer( this );
QString itext = tr(
"This is a small server example.\n"
"Connect with the client now."
);
QLabel *lb = new QLabel( itext, this );
lb->setAlignment( AlignHCenter );
infoText = new QTextView( this );
QPushButton *quit = new QPushButton( tr("Quit") , this );
connect( server, SIGNAL(newConnect(ClientSocket*)),
SLOT(newConnect(ClientSocket*)) );
connect( quit, SIGNAL(clicked()), qApp,
SLOT(quit()) );
}
~ServerInfo()
{
}
private slots:
void newConnect( ClientSocket *s )
{
infoText->append( tr("New connection\n") );
connect( s, SIGNAL(logText(const QString&)),
infoText, SLOT(append(const QString&)) );
connect( s, SIGNAL(connectionClosed()),
SLOT(connectionClosed()) );
}
void connectionClosed()
{
infoText->append( tr("Client closed connection\n") );
}
private:
QTextView *infoText;
};
To copy to clipboard, switch view to plain text mode
I have this in a form.ui.h file. (infoText text browser was created in qt designer)
#include "clientsocket.h"
#include "server.h"
void Form1::init(){
SimpleServer *server = new SimpleServer( this );
connect( server, SIGNAL(newConnect(ClientSocket*)),
SLOT(newConnect(ClientSocket*)) );
}
void Form1::newConnect( ClientSocket *s ){
infoText->append( tr("New connection\n") );
connect( s, SIGNAL(logText(const QString&)),
infoText, SLOT(append(const QString&)) );
connect( s, SIGNAL(connectionClosed()),
SLOT(connectionClosed()) );
}
void Form1::connectionClosed(){
infoText->append( tr("Client closed connection\n") );
}
#include "clientsocket.h"
#include "server.h"
void Form1::init(){
SimpleServer *server = new SimpleServer( this );
connect( server, SIGNAL(newConnect(ClientSocket*)),
SLOT(newConnect(ClientSocket*)) );
}
void Form1::newConnect( ClientSocket *s ){
infoText->append( tr("New connection\n") );
connect( s, SIGNAL(logText(const QString&)),
infoText, SLOT(append(const QString&)) );
connect( s, SIGNAL(connectionClosed()),
SLOT(connectionClosed()) );
}
void Form1::connectionClosed(){
infoText->append( tr("Client closed connection\n") );
}
To copy to clipboard, switch view to plain text mode
When I try to make, I get:
form1.h:36: error: "ClientConnect" was not declared
form1.h:36: error: "ClientConnect" was not declared
To copy to clipboard, switch view to plain text mode
as if it were an object and not a type. I'm sorry if this question sounds really stupid but I'm a beginner and believe me, I've tried all sorts of things to make it work.
Bookmarks