mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-08 08:28:39 +00:00
优化qt自定义事件逻辑
This commit is contained in:
parent
b9764cc68f
commit
a431906ecd
3 changed files with 23 additions and 9 deletions
|
@ -50,7 +50,8 @@ HEADERS += \
|
|||
qyuvopenglwidget.h \
|
||||
videoform.h \
|
||||
devicesocket.h \
|
||||
tcpserver.h
|
||||
tcpserver.h \
|
||||
qscrcpyevent.h
|
||||
|
||||
FORMS += \
|
||||
dialog.ui \
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include "qscrcpyevent.h"
|
||||
#include "devicesocket.h"
|
||||
|
||||
static const int GetDataEvent = QEvent::registerEventType(QEvent::User+1);
|
||||
class DeviceSocketEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
DeviceSocketEvent() : QEvent(QEvent::Type(GetDataEvent)){}
|
||||
};
|
||||
|
||||
DeviceSocket::DeviceSocket(QObject *parent) : QTcpSocket(parent)
|
||||
{
|
||||
connect(this, &DeviceSocket::readyRead, this, &DeviceSocket::onReadyRead);
|
||||
|
@ -47,7 +41,7 @@ qint32 DeviceSocket::recvData(quint8 *buf, qint32 bufSize)
|
|||
|
||||
bool DeviceSocket::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (event->type() == GetDataEvent) {
|
||||
if (event->type() == QScrcpyEvent::DeviceSocket) {
|
||||
onReadyRead();
|
||||
return true;
|
||||
}
|
||||
|
|
19
src/qscrcpyevent.h
Normal file
19
src/qscrcpyevent.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef QSCRCPYEVENT_H
|
||||
#define QSCRCPYEVENT_H
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
class QScrcpyEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
DeviceSocket = QEvent::User + 1,
|
||||
};
|
||||
QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)){}
|
||||
};
|
||||
|
||||
class DeviceSocketEvent : public QScrcpyEvent
|
||||
{
|
||||
public:
|
||||
DeviceSocketEvent() : QScrcpyEvent(DeviceSocket){}
|
||||
};
|
||||
#endif // QSCRCPYEVENT_H
|
Loading…
Add table
Add a link
Reference in a new issue