i am using QTcpsocket.readLine to read from a socket in a thread. it is working well otherwise but causing a segmentation failure. this the code:
Header file
#ifndef CLIENTTHREAD_H
#define CLIENTTHREAD_H
#include<QtNetwork/QTcpSocket>
#include<QThread>
{
Q_OBJECT
public:
// MainWindow *m;
// int index;
void run();
signals:
private slots:
void readFromClient();
private:
};
#endif // CLIENTTHREAD_H
#ifndef CLIENTTHREAD_H
#define CLIENTTHREAD_H
#include<QtNetwork/QTcpSocket>
#include<QThread>
class clientThread:public QThread
{
Q_OBJECT
public:
clientThread(QTcpSocket *,QObject *,QString);
// MainWindow *m;
// int index;
QString name;
void run();
signals:
void updatechat(QString,QString);
private slots:
void readFromClient();
private:
QTcpSocket *socket;
};
#endif // CLIENTTHREAD_H
To copy to clipboard, switch view to plain text mode
Source File;
#include "clientthread.h"
socket(_socket),name(_name)
{
connect(socket,SIGNAL(disconnected()),this,SLOT(terminate()));
}
void clientThread::run(){
char *data;
uint i;
i=1024;
qDebug()<<"client thread started";
}
void clientThread::readFromClient(){
char *data;
uint i;
i=1024;
[COLOR="Red"] socket->readLine(data,i);[/COLOR]
emit updatechat(tr(data),name);
}
#include "clientthread.h"
clientThread::clientThread(QTcpSocket *_socket,QObject *parent,/*int _index*/QString _name):QThread(parent),
socket(_socket),name(_name)
{
connect(socket,SIGNAL(disconnected()),this,SLOT(terminate()));
}
void clientThread::run(){
char *data;
QString s;
uint i;
i=1024;
qDebug()<<"client thread started";
}
void clientThread::readFromClient(){
char *data;
QString s;
uint i;
i=1024;
[COLOR="Red"] socket->readLine(data,i);[/COLOR]
emit updatechat(tr(data),name);
}
To copy to clipboard, switch view to plain text mode
Any Ideas why this is happening.
Please help
Bookmarks