hasnain
4th September 2010, 11:19
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>
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
Source File;
#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(te rminate()));
}
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;
socket->readLine(data,i);
emit updatechat(tr(data),name);
}
Any Ideas why this is happening.
Please help
Header file
#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
Source File;
#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(te rminate()));
}
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;
socket->readLine(data,i);
emit updatechat(tr(data),name);
}
Any Ideas why this is happening.
Please help