Hi,
I cannot figure out what is wrong with following code. Code won't compile. I've got a feeling I'm somehow creating the whole connection object wrong, but I guess you guys notice it right away if that's the case. It's interesting that I've seen at least dozen snapshots of code where the socket is created just like this. That's why I'm suspecting the mainwindow.cpp part (below).
Compiling errors:
..\muutoshallinta\client_connection.cpp: In member function 'bool client_connection::init_connection()':
..\muutoshallinta\client_connection.cpp:21: error: invalid conversion from 'QSslSocket*' to 'SOCKET'
..\muutoshallinta\client_connection.cpp:21: error: cannot convert 'const char*' to 'const sockaddr*' for argument '2' to 'int connect(SOCKET, const sockaddr*, int)'
..\muutoshallinta\client_connection.cpp:22: error: invalid conversion from 'QSslSocket*' to 'SOCKET'
..\muutoshallinta\client_connection.cpp:22: error: cannot convert 'const char*' to 'const sockaddr*' for argument '2' to 'int connect(SOCKET, const sockaddr*, int)'
..\muutoshallinta\client_connection.cpp: In member function 'bool client_connection::init_connection()':
..\muutoshallinta\client_connection.cpp:21: error: invalid conversion from 'QSslSocket*' to 'SOCKET'
..\muutoshallinta\client_connection.cpp:21: error: cannot convert 'const char*' to 'const sockaddr*' for argument '2' to 'int connect(SOCKET, const sockaddr*, int)'
..\muutoshallinta\client_connection.cpp:22: error: invalid conversion from 'QSslSocket*' to 'SOCKET'
..\muutoshallinta\client_connection.cpp:22: error: cannot convert 'const char*' to 'const sockaddr*' for argument '2' to 'int connect(SOCKET, const sockaddr*, int)'
To copy to clipboard, switch view to plain text mode
client_connection.cpp:
#include "client_connection.h"
#include "common.h"
#include <QtNetwork>
#include <stdlib.h>
#include "mainwindow.h"
client_connection::client_connection()
{
}
bool client_connection::init_connection()
{
if (!QSslSocket::supportsSsl()) {
return false;
}
ptr_socket = new QSslSocket();
if (!ptr_socket) {
connect(ptr_socket, SIGNAL(encrypted()), this, SLOT(connection_encrypted()));
connect(ptr_socket, SIGNAL(encrypted()), this, SLOT(connection_disconnected()));
/* connect(socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));*/
}
ptr_socket->connectToHostEncrypted("localhost", 555);
return true;
}
#include "client_connection.h"
#include "common.h"
#include <QtNetwork>
#include <stdlib.h>
#include "mainwindow.h"
client_connection::client_connection()
{
}
bool client_connection::init_connection()
{
if (!QSslSocket::supportsSsl()) {
return false;
}
ptr_socket = new QSslSocket();
if (!ptr_socket) {
connect(ptr_socket, SIGNAL(encrypted()), this, SLOT(connection_encrypted()));
connect(ptr_socket, SIGNAL(encrypted()), this, SLOT(connection_disconnected()));
/* connect(socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));*/
}
ptr_socket->connectToHostEncrypted("localhost", 555);
return true;
}
To copy to clipboard, switch view to plain text mode
client_connection.h
#ifndef CLIENT_CONNECTION_H
#define CLIENT_CONNECTION_H
#include <QtNetwork>
class client_connection
{
public:
client_connection();
bool init_connection();
private slots:
void connection_encrypted();
void connection_disconnected();
private:
QSslSocket *ptr_socket;
};
#endif // CLIENT_CONNECTION_H
#ifndef CLIENT_CONNECTION_H
#define CLIENT_CONNECTION_H
#include <QtNetwork>
class client_connection
{
public:
client_connection();
bool init_connection();
private slots:
void connection_encrypted();
void connection_disconnected();
private:
QSslSocket *ptr_socket;
};
#endif // CLIENT_CONNECTION_H
To copy to clipboard, switch view to plain text mode
I'm creating the connection object in mainwindow.cpp:
#ifdef FEA_CLIENT
client_connection *ptr_connection = new client_connection();
if(ptr_connection->init_connection())
{
//connection ready
}
#endif
#ifdef FEA_CLIENT
client_connection *ptr_connection = new client_connection();
if(ptr_connection->init_connection())
{
//connection ready
}
#endif
To copy to clipboard, switch view to plain text mode
Thanks in advance!
Bookmarks