My code has following structure:
include
-> myserver.h
-> mythread.h
-> mainwindow.h
src
-> myserver.cpp
-> mythread.cpp
-> mainwindow.cpp
main.cpp
MyServer class creates a new thread for each connection. In that thread, I am reading the data from the client and want to send it to mainwindow.cpp. For this, I am thinking of using signal and slots. Since I have not declared MyThread in mainwindow, I am not able to use connect().
mythread.h:
signals:
void newDataRecieved(QVector<double> x,QVector<double> y);
mythread.cpp:
void MyThread::func(){
.
.
.
emit newDataRecieved(x,yC);
}
myserver.cpp:
void MyServer::incomingConnection(qintptr socketDescriptor)
{
// We have a new connection
qDebug() << socketDescriptor << " Connecting...";
MyThread *thread = new MyThread(socketDescriptor, this);
// connect signal/slot
// once a thread is not needed, it will be beleted later
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
mainwindow.h:
public slots:
void newValues(QVector<double> x,QVector<double> y);
main.cpp:
.
.
#include "myserver.h"
int main(int argc, char *argv[])
{
.
.
w.show();
MyServer server;
server.startServer();
return a.exec();
}
Is there any way to solve this?