Hy
I would like to ask someone for help. I wanted to make a gui server so I created a gui application and in main class I created my server (because if I created it in MainWindow class I had problems with incomingConnection). It was not a problem to connect server class with mainwindow class, but problem arises when I try to connect another object declared in server class with mainwindow, I do not know how to pass object address, so I ask for help. To further illustrate my problem I attached piece of code:
#include "mainwindow.h"
#include <QApplication>
#include "server.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
Server ServerTcp;
ServerTcp.StartServer(&w);
return a.exec();
}
#include "server.h"
#include "client.h"
{
}
{
obj = object;
emit SetInfo("Started");
}
else{
emit SetInfo("Not started!");
}
}
void Server::incomingConnection(int handle)
{
Client *clientT = new Client(this);
connect(&clientT,
SIGNAL(SetInfo
(QString)),
&obj,
SLOT(GetInfo
(QString)));
clientT->SetSocket(handle);
}
#include "mainwindow.h"
#include <QApplication>
#include "server.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
Server ServerTcp;
QObject::connect(&ServerTcp,SIGNAL(SetInfo(QString)),&w,SLOT(GetInfo(QString)));
ServerTcp.StartServer(&w);
return a.exec();
}
#include "server.h"
#include "client.h"
Server::Server(QObject *parent) :
QTcpServer(parent)
{
}
void Server::StartServer(QMainWindow *object)
{
if(listen(QHostAddress::Any,1234)){
obj = object;
emit SetInfo("Started");
}
else{
emit SetInfo("Not started!");
}
}
void Server::incomingConnection(int handle)
{
Client *clientT = new Client(this);
connect(&clientT,SIGNAL(SetInfo(QString)),&obj,SLOT(GetInfo(QString)));
clientT->SetSocket(handle);
}
To copy to clipboard, switch view to plain text mode
Thank you for reply
Bookmarks