PDA

View Full Version : exited with code -1073741819



Con Nít
25th January 2011, 12:41
i made a new class inheriting QTcpsocket,with the following content :

mytcpsocket.h

#ifndef MYTCPSOCKET_H
#define MYTCPSOCKET_H

#include <QTcpSocket>
#include <QString>
#include <qvariant.h>

class MyTcpSocket : public QTcpSocket
{
public:
MyTcpSocket(QObject* parent = 0);
void setClientUser(const QString &strClientUser);
void setGroup(const int &iGroup);
QString getClientUser();
int getGroup();
private:
QString strClientUser;
int iGroup;
};

#endif // MYTCPSOCKET_H

mytcpsocket.cpp

#include "mytcpsocket.h"

MyTcpSocket::MyTcpSocket(QObject* parent) : QTcpSocket(parent)
{
//strClientUser = tr("Student");
iGroup = 0;
}
void MyTcpSocket::setClientUser(const QString &strClientUser){
this->strClientUser = strClientUser;
}
void MyTcpSocket::setGroup(const int &iGroup){
this->iGroup = iGroup;
}
QString MyTcpSocket::getClientUser(){
return strClientUser;
}
int MyTcpSocket::getGroup(){
return iGroup;
}


whenever i used the method of setClientUser or getClientUser
the program got exited with code -1073741819

but the methods of setGroup and getGroup run properly.

help me get to know and solve this problem.thank you so much

Stef
25th January 2011, 13:36
These methods + implementation are correct so they should work. Perhaps you are not properly creating a new MyTcpSocket object before calling the methods of this object? Such as:


MyTcpSocket* socket = new MyTcpSocket

Can you show us the code on which it fails?

Con Nít
25th January 2011, 16:21
this is my code :

client side,when connected() occurs :


if(socket == NULL) return;
if(socket->state() != QAbstractSocket::ConnectedState ) return;
QString msg = "NICK";
QVariant data = QVariant(ui->nick->text().toLatin1());
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_2);
out << (quint32) 0;
out << msg;
out << data;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));

socket->write(block);
socket->flush();

site sever when receive a message from cilent :


MyTcpSocket* socket = static_cast<MyTcpSocket*>(sender());

if (socket == NULL) return;
if ( socket->state() != QAbstractSocket::ConnectedState ) return;

QDataStream in(socket);
in.setVersion(QDataStream::Qt_4_2);

if (blockSize == 0) {
if (socket->bytesAvailable() < (int)sizeof(quint32)) return;
in >> blockSize;
}

if (socket->bytesAvailable() < blockSize) return;

QString msgString;
QVariant msgData;
in >> msgString;
in >> msgData;

if(msgString != "NICK"){
onMessage( msgString, msgData );
}else{
socket->setGroup(1);
qDebug() << "value of group is : " << socket->getGroup();
socket->setClientUser(msgData.toString());
qDebug() << "ok";
}
blockSize = 0;
if (socket->bytesAvailable() > 0) receiveMessage();

Application sever output :

value of group is : 1
D:\ProGram\QT\SimpleChat-build-desktop\SimpleChatServer\debug\SimpleChatServer.ex e exited with code -1073741819

Con Nít
26th January 2011, 06:35
someone help me :(:(:(

ChrisW67
26th January 2011, 06:41
What is in msgData at line 25 (last listing)? Can it be converted to a string?

Edit, more:
-1073741819 is 0xC0000003, which in Windows land means Access violation. This would normally be caused by access through an invalid pointer, or using a reference to an object that no longer exists.

Con Nít
26th January 2011, 07:02
I try to use qDebug() << "value of data is : " << msgData.toString(); and it prints out the exact name the user input from client side
instead of using socket->setClientUser(msgData.toString()); i try socket-> setclientuser("Cuong"); or socket-> setclientuser(tr("Cuong"));<<< but the same error occurs

Con Nít
27th January 2011, 06:09
Somebody help me, I need it :(:(:(

ChrisW67
27th January 2011, 22:04
Is "socket" still pointing at a valid object?
Have you determined the exact line that the error is triggered by?