Hi all,
I have a MainWindow class, which instantiates a 'Connector' class. The Connector is responsible for making TCP socket connections, and reading data and putting into a shared buffer.
The data read from the TCP socket is to be processed by some method in the MainWindow class. My concern is, while the main window is processing with the data, further signals from the TCPSocket (data ready) might be lost, as the event loop of 'Connector' is blocked.
So I want to push the 'reading of data' from the TCPSocket to a different thread so that the event loop is not blocked while processing of data is going on.
How do I achieve this ? Should I use runnable or qthread ?
The Connector looks like this :
public :
Connector
(QString hostname, quint16 port, TemanejoMainWindow
* p
);
~Connector();
public slots:
void readData();
void connectToHost();
public :
Connector(QString hostname, quint16 port, TemanejoMainWindow* p);
~Connector();
public slots:
void getError(QAbstractSocket::SocketError);
void readData();
void connectToHost();
To copy to clipboard, switch view to plain text mode
The constructor binds the signals and slots as :
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
tcpSocket = new QTcpSocket(this);
connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)), this,
SLOT(getError(QAbstractSocket::SocketError)));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
To copy to clipboard, switch view to plain text mode
The method "connectToHost" makes the TCP connection, while readData() is executed everytime data is ready to be read. To me, pushing readData
method to a new thread makes sense.
Any help on how to do this ?
Best regards
Bookmarks