Signal isn't emitted from socket
Hi,
Signal readyRead() isn't emitted from socket. Why? In this video it's working well: http://www.youtube.com/watch?v=j9uAfTAZrdM
Output:
Quote:
Connecting...
Connected!
we wrote: 21
Disconnected!
SignalSocket.pro
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2013-08-14T13:28:42
#
#-------------------------------------------------
QT += core
QT += network
QT -= gui
TARGET = SignalSocket
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
sockettest.cpp
HEADERS += \
sockettest.h
main.cpp
Code:
#include <QCoreApplication>
#include "sockettest.h"
int main(int argc, char *argv[])
{
SocketTest mTest;
mTest.Test();
return a.exec();
}
sockettest.h
Code:
#ifndef SOCKETTEST_H
#define SOCKETTEST_H
#include <QObject>
#include <QDebug>
#include <QTcpSocket>
#include <QAbstractSocket>
{
Q_OBJECT
public:
explicit SocketTest
(QObject *parent
= 0);
void Test();
signals:
public slots:
void connected();
void disconnected();
void bytesWritten(qint64 bytes);
void readyRead();
private:
};
#endif // SOCKETTEST_H
sockettest.cpp
Code:
#include "sockettest.h"
SocketTest
::SocketTest(QObject *parent
) :{
}
void SocketTest::Test() {
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
qDebug() << "Connecting...";
socket->connectToHost("google.com", 443);
if (!socket->waitForConnected(1000)) {
qDebug() << "Error: " << socket->errorString();
}
}
void SocketTest::connected() {
qDebug() << "Connected!";
socket->write("HEAD / HTTP/1.0\r\n\r\n\r\n");
}
void SocketTest::disconnected() {
qDebug() << "Disconnected!";
}
void SocketTest::bytesWritten(qint64 bytes) {
qDebug() << "we wrote: " << bytes;
}
void SocketTest::readyRead() {
qDebug() << "Reading...";
qDebug() << socket->readAll();
}
Thank you!
Re: Signal isn't emitted from socket
Why would it emit readyRead()? HTTPS servers do not send any data upon connection. The SSL handshake is initiated by the client.
Re: Signal isn't emitted from socket
Thank you for reply!
But in video it works!
Re: Signal isn't emitted from socket
Apparently the video does something else than your code. Does your connected() slot ever get called?
By the way, are you aware you are connecting to a service that expects an SSL handshake?