QT - QObject::connect: No such slot QObject::dataReceiv

   
Vista:

QObject::connect: No such slot QObject::dataReceiv

Publicado por Pedro (1 intervención) el 06/07/2009 09:47:26
Estoy intentando hacer una aplicación utilizando QSocketNotifier para detectar llegada de sockets. La aplicación compila bien, pero al arrancar dice:
QObject::connect: No such slot QObject::dataReceived()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'unnamed')

No se porque dice no such slot porque se supone que está definido. ¿Qué tengo mal?. El código es el siguiente:

//SocketParser.h
#ifndef SOCKETPARSER_H_
#define SOCKETPARSER_H_

#include <sys/types.h>
#include <qobject.h>

#define BUFFERSIZE 1024

class socket_parser:QObject
{

public:
void launchServer(int port1, int port2 = 0);
static int parse(const char buffer[BUFFERSIZE]);
static void send_PlayerDone(const char *idPlayer);
static void send_Alive();

public slots:
virtual void dataReceived();

private:
static char* getAttributeString(const char *buffer, char *attrName);
static int getAttributeValue(const char *buffer, char *attrName);
static bool getAttributeBoolean(const char *buffer, char *attrName);

public:
static struct sockaddr_in remote;
static unsigned int inputPort;
static unsigned int outputPort;

private:
static int serversock;
};

#endif /*SOCKETPARSER_H_*/

SocketParser.cpp

#include "SocketParser.h"
#include "manager.h"
//#include <string.h>

#include <netdb.h> // hostent struct, gethostbyname()
#include <arpa/inet.h> // inet_ntoa() to format IP address
#include <netinet/in.h> // in_addr structure
#include <errno.h> // error handling
#include <iostream> // cout and endl functions

#include <iostream> // cout and endl functions
#include <stdio.h>
#include "string.h"
#include "stdlib.h"
//#include <qobject.h>

#include <qsocketnotifier.h>

#define AM_DBG
#ifndef AM_DBG
#define AM_DBG if(0)
#endif

#define MAXPENDING 5 // Max connection requests
#define DEFAULT_PORT 1234

int socket_parser::serversock = 0;
struct sockaddr_in socket_parser::remote = {0, 0, {0}, {"0"}};
unsigned int socket_parser::inputPort = 0;
unsigned int socket_parser::outputPort = 0;

void socket_parser::dataReceived(){

fprintf(stdout, "DATA!!! ");
char buffer[BUFFERSIZE];
int received = 1;
socklen_t len = sizeof(socket_parser::remote);

// Clear buffer data
memset(buffer, 0, BUFFERSIZE);
// Receive message
if ((received = recvfrom(socket_parser::serversock, buffer, BUFFERSIZE, 0,
(struct sockaddr *)&socket_parser::remote, &len)) < 0) {
std::cerr << "Failed to receive bytes from client. Error(" << errno << "): " << strerror(errno) <<std::endl;
return;
}
else
socket_parser::parse(buffer);
}

int socket_parser::parse(const char buffer[BUFFERSIZE])
{
// Parse string
printf("SOCKET RECIBIDO!!!!!!!"); fflush(stdout);
}

//LLAMADO POR EL MAIN DE LA APPL
void socket_parser::launchServer(int port1, int port2) {
struct sockaddr_in echoserver;

if (port1 <=0)
socket_parser::inputPort = DEFAULT_PORT;
else
socket_parser::inputPort = port1;

if (port2 <=0)
socket_parser::outputPort = socket_parser::inputPort;
else
socket_parser::outputPort = port2;

// Create the TCP socket
if ((socket_parser::serversock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
perror("Failed to create socket"); exit(1);
}
// Construct the server sockaddr_in structure
memset(&echoserver, 0, sizeof(echoserver)); // Clear struct
echoserver.sin_family = AF_INET; // Internet/IP
echoserver.sin_addr.s_addr = htonl(INADDR_ANY); // Incoming addr
echoserver.sin_port = htons(inputPort); // server port

// Bind the server socket
if (bind(socket_parser::serversock, (struct sockaddr *) &echoserver,
sizeof(echoserver)) < 0) {
perror("Failed to bind the server socket"); exit(1);
}

QSocketNotifier *sn = new QSocketNotifier(socket_parser::serversock, QSocketNotifier::Read);

this->connect( sn, SIGNAL(activated(int)),this, SLOT(dataReceived()) );

fprintf(stdout, "adviewer_qt: Waiting for clients... ");

while (true){

sleep(1000);
}

fprintf(stdout, "Closing server... ");
close(socket_parser::serversock);
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder