#ifndef MY_CLASS_H
#define MY_CLASS_H
#include <QObject>
#include <QThread>
#include <QIODevice>
{
Q_OBJECT
public:
~MyClass();
some other members ...
private:
some other members ...
};
#endif // MY_CLASS_H
#ifndef MY_CLASS_H
#define MY_CLASS_H
#include <QObject>
#include <QThread>
#include <QIODevice>
class MyClass : public QThread
{
Q_OBJECT
public:
explicit MyClass(QIODevice* inputDevice = 0, QObject *parent = 0);
~MyClass();
void sendData(quint8 id, QByteArray data);
some other members ...
private:
QIODevice* m_pInputDevice;
QIODevice* m_pForwardDevice;
some other members ...
};
#endif // MY_CLASS_H
To copy to clipboard, switch view to plain text mode
#include "MyClass.h"
QThread(parent
), m_pInputDevice
(inputDevice
), m_pForwardDevice
(NULL), m_bForwardData
(false) {
}
MyClass::~MyClass()
{
bool bRet;
if(m_pInputDevice)
{
Qt::DirectConnection, Q_RETURN_ARG(bool, bRet));
if(bRet)
{
Qt::DirectConnection);
}
}
if(m_pForwardDevice)
{
Qt::DirectConnection, Q_RETURN_ARG(bool, bRet));
if(bRet)
{
Qt::DirectConnection);
}
}
}
// use case example
void MyClass
::sendData(quint8 id,
QByteArray data
) {
bool bRet;
if (!m_pInputDevice)
{
emit error("Input device not set!");
return;
}
Qt::DirectConnection, Q_RETURN_ARG(bool, bRet));
if(!bRet)
{
emit error("Input device is not open");
return;
}
QFlags<QIODevice::OpenModeFlag> openMode;
Qt::DirectConnection, Q_RETURN_ARG(QFlags<QIODevice::OpenModeFlag>, openMode));
{
emit error("Input device is in read only mode!");
return;
}
// some processing...
qint64 bytesWritten;
Qt
::DirectConnection, Q_RETURN_ARG
(qint64, bytesWritten
), Q_ARG
(QByteArray, data
));
if(bytesWritten == -1)
emit error("Data output failed.");
}
#include "MyClass.h"
MyClass::MyClass(QIODevice* inputDevice, QObject *parent) :
QThread(parent), m_pInputDevice(inputDevice), m_pForwardDevice(NULL), m_bForwardData(false)
{
}
MyClass::~MyClass()
{
bool bRet;
if(m_pInputDevice)
{
QMetaObject::invokeMethod(m_pInputDevice, "isOpen",
Qt::DirectConnection, Q_RETURN_ARG(bool, bRet));
if(bRet)
{
QMetaObject::invokeMethod(m_pInputDevice, "close",
Qt::DirectConnection);
}
}
if(m_pForwardDevice)
{
QMetaObject::invokeMethod(m_pForwardDevice, "isOpen",
Qt::DirectConnection, Q_RETURN_ARG(bool, bRet));
if(bRet)
{
QMetaObject::invokeMethod(m_pForwardDevice, "close",
Qt::DirectConnection);
}
}
}
// use case example
void MyClass::sendData(quint8 id, QByteArray data)
{
bool bRet;
if (!m_pInputDevice)
{
emit error("Input device not set!");
return;
}
QMetaObject::invokeMethod(m_pInputDevice, "isOpen",
Qt::DirectConnection, Q_RETURN_ARG(bool, bRet));
if(!bRet)
{
emit error("Input device is not open");
return;
}
QFlags<QIODevice::OpenModeFlag> openMode;
QMetaObject::invokeMethod(m_pInputDevice, "openMode",
Qt::DirectConnection, Q_RETURN_ARG(QFlags<QIODevice::OpenModeFlag>, openMode));
if (openMode == QIODevice::ReadOnly)
{
emit error("Input device is in read only mode!");
return;
}
// some processing...
qint64 bytesWritten;
QMetaObject::invokeMethod(m_pInputDevice, "write",
Qt::DirectConnection, Q_RETURN_ARG(qint64, bytesWritten), Q_ARG(QByteArray, data));
if(bytesWritten == -1)
emit error("Data output failed.");
}
To copy to clipboard, switch view to plain text mode
#ifndef SSL_IO_DEVICE_H
#define SSL_IO_DEVICE_H
#include <QSslSocket>
class SslIODevice : public QSslSocket
{
Q_OBJECT
public:
explicit SslIODevice();
~SslIODevice();
//For each QIODevice method I use
Q_INVOKABLE [I]returnType[/I] method([I]args[/I]);
some other members ...
private:
some private members ...
};
#endif // SSL_IO_DEVICE_H
#ifndef SSL_IO_DEVICE_H
#define SSL_IO_DEVICE_H
#include <QSslSocket>
class SslIODevice : public QSslSocket
{
Q_OBJECT
public:
explicit SslIODevice();
~SslIODevice();
//For each QIODevice method I use
Q_INVOKABLE [I]returnType[/I] method([I]args[/I]);
some other members ...
private:
some private members ...
};
#endif // SSL_IO_DEVICE_H
To copy to clipboard, switch view to plain text mode
#include "SslIODevice.h"
SslIODevice::SslIODevice() :
QSslSocket()
{
}
SslIODevice::~SslIODevice()
{
}
//For each QIODevice method I use
[I]returnType[/I] SslIODevice::method([I]args[/I])
{
return QSslSocket::method([I]args[/I]);
}
#include "SslIODevice.h"
SslIODevice::SslIODevice() :
QSslSocket()
{
}
SslIODevice::~SslIODevice()
{
}
//For each QIODevice method I use
[I]returnType[/I] SslIODevice::method([I]args[/I])
{
return QSslSocket::method([I]args[/I]);
}
To copy to clipboard, switch view to plain text mode
Bookmarks