Unhandled exception when using QtNetwork under visual studio 2010
-
hello,
I created a server application under QtCreator, and it works. Now, i create a client application under Visual Studio 2010. But, when i try to connect to my server , i have an unhandled exception, and the application crashed:
@Unhandled exception at 0x56cd6ab4 in viewer.exe: 0xC0000005: Access violation reading location 0xa1f9074d.@
here is my code:
@viewer::viewer(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);QObject::connect(ui.open,SIGNAL(clicked ( ) ),this,SLOT(ouvrirDialogue()));
QTcpSocket *socket = new QTcpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
connect(socket, SIGNAL(connected()), this, SLOT(connecte()));
connect(socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));// Sphere
tailleMessage = 0;
blockSize =0;
}
void viewer::on_message_returnPressed()
{
on_boutonEnvoyer_clicked();
}
void viewer::on_boutonConnexion_clicked()
{
ui.boutonConnexion->setEnabled(false);socket->abort(); // On désactive les connexions précédentes s'il y en a socket->connectToHost(ui.serveurIP->text(), ui.serveurPort->value()); // On se connecte au serveur demandé
}
void viewer::deconnecte()
{
}
void viewer::connecte()
{ui.boutonConnexion->setEnabled(true);
}
void viewer::erreurSocket(QAbstractSocket::SocketError erreur)
{
switch(erreur) // On affiche un message différent selon l'erreur qu'on nous indique
{
case QAbstractSocket::HostNotFoundError:
QMessageBox::information(this, "connexion serveur","<em>ERREUR : le serveur n'a pas pu être trouvé. Vérifiez l'IP et le port.</em>");
break;
case QAbstractSocket::ConnectionRefusedError:
QMessageBox::information(this, "connexion serveur","<em>ERREUR : le serveur a refusé la connexion. Vérifiez si le programme "serveur" a bien été lancé. Vérifiez aussi l'IP et le port.</em>");
break;
case QAbstractSocket::RemoteHostClosedError:
QMessageBox::information(this, "connexion serveur","<em>ERREUR : le serveur a coupé la connexion.</em>");
break;
default:
QMessageBox::information(this, "connexion serveur","<em>ERREUR : ");
}
}@
Any help please and thanks -
Where is the crash in the server app or in the client app?
Nevertheless, I am suggesting that you are running the applications in debug mode in the debugger. That should give you a glue where the problem happens.