mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +00:00
优化qt自定义事件处理逻辑
This commit is contained in:
parent
a431906ecd
commit
c8f8101f72
3 changed files with 13 additions and 6 deletions
|
@ -9,8 +9,6 @@ DeviceSocket::DeviceSocket(QObject *parent) : QTcpSocket(parent)
|
|||
connect(this, &DeviceSocket::readyRead, this, &DeviceSocket::onReadyRead);
|
||||
connect(this, &DeviceSocket::aboutToClose, this, &DeviceSocket::quitNotify);
|
||||
connect(this, &DeviceSocket::disconnected, this, &DeviceSocket::quitNotify);
|
||||
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
DeviceSocket::~DeviceSocket()
|
||||
|
@ -39,13 +37,13 @@ qint32 DeviceSocket::recvData(quint8 *buf, qint32 bufSize)
|
|||
return m_dataSize;
|
||||
}
|
||||
|
||||
bool DeviceSocket::eventFilter(QObject *watched, QEvent *event)
|
||||
bool DeviceSocket::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QScrcpyEvent::DeviceSocket) {
|
||||
onReadyRead();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return QTcpSocket::event(event);
|
||||
}
|
||||
|
||||
void DeviceSocket::onReadyRead()
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
qint32 recvData(quint8* buf, qint32 bufSize);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
bool event(QEvent *event);
|
||||
|
||||
protected slots:
|
||||
void onReadyRead();
|
||||
|
|
|
@ -1,19 +1,28 @@
|
|||
#ifndef QSCRCPYEVENT_H
|
||||
#define QSCRCPYEVENT_H
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
class QScrcpyEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
DeviceSocket = QEvent::User + 1,
|
||||
Control,
|
||||
};
|
||||
QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)){}
|
||||
};
|
||||
|
||||
// DeviceSocketEvent
|
||||
class DeviceSocketEvent : public QScrcpyEvent
|
||||
{
|
||||
public:
|
||||
DeviceSocketEvent() : QScrcpyEvent(DeviceSocket){}
|
||||
};
|
||||
|
||||
// ControlEvent
|
||||
class ControlEvent : public QScrcpyEvent
|
||||
{
|
||||
public:
|
||||
ControlEvent() : QScrcpyEvent(Control){}
|
||||
};
|
||||
#endif // QSCRCPYEVENT_H
|
||||
|
|
Loading…
Add table
Reference in a new issue