problem in QAbstractSocket::SocketError
Hi everyone,
I am using qt 4.6.2. I am trying to use socket error for unplugging the network cable.I am using connect function to get the error.But when i removed the cable no error is occurring .
Code:
switch(err)
{
case 0:QMessageBox::critical(0,
"connection error",
"The connection was refused by the peer (or timed out).",
QMessageBox::Ok);
break;
break;
break;
break;
qDebug()<<"error is ......."<<err;
break;
}
Is there anything to do more ?
Re: problem in QAbstractSocket::SocketError
After remove network cable do you use any socket function?
I think if remove cable you receive stateChanged or disconnected signal. And receive error only if you do any socket operation after cable removing.
Re: problem in QAbstractSocket::SocketError
I have function for stateChanged and disconnected signal.But when i removed the cable no one is called.
Re: problem in QAbstractSocket::SocketError
ok. i try code and will tell later. But say me plz, what class is clt ?
And your OS plz.
Re: problem in QAbstractSocket::SocketError
.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTcpSocket>
#include <QDateTime>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
private slots:
void on_pushButton_clicked();
void st_connected();
void st_disconnected();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(socket,SIGNAL(connected()),this,SLOT(st_connected()));
connect(socket,SIGNAL(disconnected()),this,SLOT(st_disconnected()));
}
MainWindow::~MainWindow()
{
delete ui;
delete socket;
}
void MainWindow::on_pushButton_clicked()
{
socket->connectToHost("adsl.by", 80);
}
void MainWindow::st_connected()
{
ui
->textEdit
->append
("Connected at " + QDateTime::currentDateTime().
toString("hh:mm:ss dd.MM.yyyy"));
}
void MainWindow::st_disconnected()
{
ui
->textEdit
->append
("Disconnected at " + QDateTime::currentDateTime().
toString("hh:mm:ss dd.MM.yyyy"));
}
{
ui
->textEdit
->append
("Error " + socket
->errorString
() + " at " + QDateTime::currentDateTime().
toString("hh:mm:ss dd.MM.yyyy"));
}
{
ui
->textEdit
->append
("State change to " + statetoString
(socketState
) + " at " + QDateTime::currentDateTime().
toString("hh:mm:ss dd.MM.yyyy"));
}
void MainWindow::on_pushButton_2_clicked()
{
if(socket->isOpen())
socket->disconnectFromHost();
}
{
switch(socketState)
{
case QAbstractSocket::UnconnectedState : statestring
="the socket is not connected";
break;
case QAbstractSocket::HostLookupState : statestring
="the socket is performing a host name lookup";
break;
case QAbstractSocket::ConnectingState : statestring
="the socket has started establishing a connection";
break;
case QAbstractSocket::ConnectedState : statestring
="a connection is established";
break;
case QAbstractSocket::BoundState : statestring
="the socket is bound to an address and port";
break;
case QAbstractSocket::ClosingState : statestring
="the socket is about to close";
break;
break;
default: statestring="unknown state";
}
return statestring;
}
i'm coded and have next result when remove cable after connect button clicked
Code:
State change to the socket is performing a host name lookup at 21:42:39 11.03.2011
State change to the socket has started establishing a connection at 21:42:40 11.03.2011
State change to a connection is established at 21:42:40 11.03.2011
Connected at 21:42:40 11.03.2011
Error The remote host closed the connection at 21:42:51 11.03.2011
State change to the socket is about to close at 21:42:51 11.03.2011
State change to the socket is not connected at 21:42:51 11.03.2011
Disconnected at 21:42:51 11.03.2011
Re: problem in QAbstractSocket::SocketError
Thanks for reply .But the above code is not working for me when i removed the cable.
I am using fedora 11 (64bit linux kernel 2.6.29) .The clt is a object of client class which inherits QTcpSocket class.
Re: problem in QAbstractSocket::SocketError
Maybe it's platform specific or network card driver problem.
If you want known interface state try use QNetworkConfiguration
Re: problem in QAbstractSocket::SocketError
Quote:
Originally Posted by
sattu
Hi everyone,
I am using qt 4.6.2. I am trying to use socket error for unplugging the network cable.I am using connect function to get the error.But when i removed the cable no error is occurring .
Is there anything to do more ?
http://doc.trolltech.com/latest/qnet....html#isOnline
Re: problem in QAbstractSocket::SocketError
QNetworkConfigurationManager class was introduced in Qt 4.7.But i am using 4.6.2.So how can i add this class in my qt application ?
Re: problem in QAbstractSocket::SocketError
Re: problem in QAbstractSocket::SocketError
I tried the program in qt 4.7 (os xp2) and it is working fine.I think there is some problem in qt4.6.2
thanks