No reception of NewConnection signal
-
Well, I've tried your code in my PC ... and it works :)
Just a strange thing, but it's not dependent on your code. Qt Creator does not show printf messages in "Application Output". But if you launch your program in a console, you'll see the message (I put a printf in NewConnection slot).
-
-
well, the only thing left is that I can post my code and you'll check for any diff ...
@
#ifndef GAMESERVER_H
#define GAMESERVER_H#include <QtCore>
#include <QtNetwork>class CGameEngineServer;
class CGameEngine : public QThread
{
Q_OBJECTquint16 m_engineport;
public:
/** Constructeur par défaut */
CGameEngine(QObject *parent = 0) : QThread(parent), MyEngineServer(0) { }/** Destructeur */ ~CGameEngine() { } /** StartProcess : Lance le serveur de jeu local et gère la partie engineport : Port d'écoute du serveur local de jeu placeavailable : Nombre maximum de joueur à la table RETURN : GAMEENGINE_CORRECT ou GAMEENGINE_ERREUR **/ void StartProcess(quint16 engineport, int placeavailable); void run();
private:
CGameEngineServer* MyEngineServer;
};class CGameEngineServer : public QTcpServer
{
Q_OBJECTpublic:
CGameEngineServer(QObject *parent = 0) : QTcpServer(parent) { }bool Listen(quint16 port); void Close();
protected:
//void incomingConnection(int socketDescriptor);private:
QVector<QTcpSocket*> m_VectorClient;
quint16 tailleMessage;signals:
void MessageToRead(QString);public slots:
void NewConnection() { printf("NEW CONNECTION!!!\n"); }
void ReadMessage() { }
};#endif // GAMESERVER_H
@@
#include "gameserver.h"void CGameEngine::StartProcess(quint16 engineport, int placeavailable)
{
m_engineport = engineport;
// m_MaxPlayer = placeavailable;start();
}
void CGameEngine::run()
{
/* Create the server object /
MyEngineServer = new CGameEngineServer();
/ Start listenning on port in arg /
if (!MyEngineServer->Listen(m_engineport)) exit();
/ Connect signals between MyEngineServer and this to specify processes at a new incoming message */
QObject::connect(MyEngineServer, SIGNAL(MessageToRead(QString)), this, SLOT(MessageToRead(QString)));
exec();
}bool CGameEngineServer::Listen(quint16 port)
{
bool result = listen(QHostAddress::LocalHost, port);
if (result)
{
printf("Local Game Engine Server listenning on port %d...\n", port);
/* make connection for a new connction */
QObject::connect(this, SIGNAL(newConnection()), this, SLOT(NewConnection()));
}
else
{
printf("Unable for Local Game Engine Server to listen on port %d...\n", port);
}
return result;
}
@@
#include <QtCore/QCoreApplication>#include "gameserver.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CGameEngine MyGameEngine;
MyGameEngine.StartProcess(8500, 2);return a.exec();
}
@I hope that this will help you solve your problem ...
-
not better.....
The only difference between your code and mine is that the CGameEngine and CGameEngineServer are available via a library (ifdef GAMENETWORK_LIBdefine GAMENETWORK_EXPORT Q_DECL_EXPORT
#else
define GAMENETWORK_EXPORT Q_DECL_IMPORT
#endif)
==> May cause the issue?
-
I progress...
When removing all classes access by library and directly insert .h and .cpp files into my app folder, it workd fine!!!!Thanks a lot.
But... I would like to understand why it does not work when using StartProcess from the CGameEngine got from a library...!!!!