Hi all,
i have this Server but whenever i try to connect to it from the client side
the incommingConnection is not being executed
can anyone help me to know the reason and how to fix it ?
Thanks in advance.
Server:
#include "server.h"
#include "ui_server.h"
#include <myclient.h>
#include <QtCore>
#include <QtGui>
#include <QTcpServer>
#include <QTcpSocket>
ui(new Ui::server)
{
ui->setupUi(this);
UserModel= new QFileSystemModel(this);
UserModel = new QFileSystemModel(this);
UserModel->setRootPath(rPath);
ui->UserListView->setModel(UserModel);
ui->UserListView->setRootIndex(index);
UserFileModel = new QFileSystemModel(this);
UserFileModel
->setFilter
(QDir::NoDotAndDotDot |
QDir::Files |
QDir::AllDirs);
ui->UserFilesTableView->setModel(UserFileModel);
ui->UserFilesTableView->resizeColumnsToContents();
ui->UserFilesTableView->setColumnWidth(3,266);
}
server::~server()
{
delete ui;
}
void server::on_StartPushButton_2_clicked()
{
// starting up the server on port number 1234
if(mServer->isListening())
{
QMessageBox::information(this,
"Start Up",
"The Server is already running");
return;
}
{
QMessageBox::information(this,
"Start Up",
"The Server Has Started");
}
else
{
QMessageBox::information(this,
"Start Up",
"The Server failed to Start up");
}
}
void server::on_shutdownPushButton_8_clicked()
{
//shutting down the server
if(!mServer->isListening())
{ QMessageBox::information(this,
"Shutdown",
"The Server is Already Turned Off");
return;
}
mServer->close();
QMessageBox::information(this,
"Shutdown",
"The Server is Turned Off");
}
void server::incomingConnection(int handle) //-----> this is never executed , i add a qDebug but it never shows
{
//when there is an incomming connection it is set to a client
myClient *mClient = new myClient(this);
mClient->SetSocket(handle);
}
#include "server.h"
#include "ui_server.h"
#include <myclient.h>
#include <QtCore>
#include <QtGui>
#include <QTcpServer>
#include <QTcpSocket>
server::server(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::server)
{
ui->setupUi(this);
mServer=new QTcpServer(this);
QString rPath="whateverpath";
UserModel= new QFileSystemModel(this);
UserModel = new QFileSystemModel(this);
UserModel->setRootPath(rPath);
QModelIndex index= UserModel->index(rPath);
ui->UserListView->setModel(UserModel);
ui->UserListView->setRootIndex(index);
UserFileModel = new QFileSystemModel(this);
UserFileModel->setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::AllDirs);
ui->UserFilesTableView->setModel(UserFileModel);
ui->UserFilesTableView->resizeColumnsToContents();
ui->UserFilesTableView->setColumnWidth(3,266);
}
server::~server()
{
delete ui;
}
void server::on_StartPushButton_2_clicked()
{
// starting up the server on port number 1234
if(mServer->isListening())
{
QMessageBox::information(this,"Start Up","The Server is already running");
return;
}
if(mServer->listen(QHostAddress::Any,1234))
{
QMessageBox::information(this,"Start Up","The Server Has Started");
}
else
{
QMessageBox::information(this,"Start Up","The Server failed to Start up");
}
}
void server::on_shutdownPushButton_8_clicked()
{
//shutting down the server
if(!mServer->isListening())
{ QMessageBox::information(this,"Shutdown","The Server is Already Turned Off");
return;
}
mServer->close();
QMessageBox::information(this,"Shutdown","The Server is Turned Off");
}
void server::incomingConnection(int handle) //-----> this is never executed , i add a qDebug but it never shows
{
//when there is an incomming connection it is set to a client
myClient *mClient = new myClient(this);
mClient->SetSocket(handle);
}
To copy to clipboard, switch view to plain text mode
Client:
#include "myclient.h"
#include "mytask.h"
#include <QtCore>
myClient
::myClient(QObject *parent
) :{
}
void myClient::SetSocket(int Descriptor)
{
connect(socket,SIGNAL(connected()),this,SLOT(connected()));
connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected()));
connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));
socket->setSocketDescriptor(Descriptor);
qDebug() << "client connected";
}
void myClient::connected()
{
qDebug() << "client connected event";
}
void myClient::disconnected()
{
qDebug() << "client disconnected";
}
void myClient::readyRead()
{
//do something
}
#include "myclient.h"
#include "mytask.h"
#include <QtCore>
myClient::myClient(QObject *parent) :
QObject(parent)
{
}
void myClient::SetSocket(int Descriptor)
{
socket = new QTcpSocket(this);
connect(socket,SIGNAL(connected()),this,SLOT(connected()));
connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected()));
connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));
socket->setSocketDescriptor(Descriptor);
qDebug() << "client connected";
}
void myClient::connected()
{
qDebug() << "client connected event";
}
void myClient::disconnected()
{
qDebug() << "client disconnected";
}
void myClient::readyRead()
{
//do something
}
To copy to clipboard, switch view to plain text mode
Bookmarks