PDA

View Full Version : Very simple problem with QServerSocket and Qsocket



eter
2nd November 2006, 20:07
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 );

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;
};



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") );
}



When I try to make, I get:



form1.h:36: error: "ClientConnect" was not declared


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.

Elgerton
3rd November 2006, 08:51
For me it is always easier to take a look at the generated from1.h file. Maybe Designer put something weird in the ui file. Can you post the part where the error occured?

Just to make it clear: The first code quotation is a h-file!? The second one is a cpp-file!?

wysota
4th November 2006, 08:07
Could you show us a part of code where ClientConnect is used? What is ClientConnect anyway?