mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
fix highgrade server error
This commit is contained in:
parent
982a0dd4d0
commit
708febed6c
@ -1,17 +1,63 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QQtApplication>
|
#include <QQtApplication>
|
||||||
#include "qqtobjectmanager.h"
|
#include "qqtobjectmanager.h"
|
||||||
|
#include "qqtprotocol.h"
|
||||||
|
#include "qqtserver2protocolmanager.h"
|
||||||
|
|
||||||
|
typedef QObject* ( *Constructor ) ( QObject* parent );
|
||||||
|
template<typename T>
|
||||||
|
static QObject* constructorHelper ( QObject* parent = 0 )
|
||||||
|
{
|
||||||
|
pline() << "created ";
|
||||||
|
return new T ( parent );
|
||||||
|
}
|
||||||
|
template<typename dst_type, typename src_type>
|
||||||
|
static dst_type pointer_cast ( src_type src )
|
||||||
|
{
|
||||||
|
return *static_cast<dst_type*> ( static_cast<void*> ( &src ) );
|
||||||
|
}
|
||||||
|
|
||||||
int main ( int argc, char* argv[] )
|
int main ( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
QQtApplication a ( argc, argv );
|
QQtApplication a ( argc, argv );
|
||||||
|
|
||||||
QQtObjectFactory::registerObject<QObject>();
|
QQtObjectFactory::registerObject<QObject>();
|
||||||
QObject* o = QQtObjectFactory::createObject ( "QObject" );
|
// QObject* o = QQtObjectFactory::createObject ( "QObject" );
|
||||||
pline() << o;
|
// pline() << o;
|
||||||
|
|
||||||
|
// QQtObjectFactory::registerObject<QQtProtocol>();
|
||||||
|
// QObject* obj = QQtObjectFactory::createObject ( "QQtProtocol" );
|
||||||
|
// QQtProtocol* protocol = dynamic_cast<QQtProtocol*> ( obj );
|
||||||
|
// pline() << protocol;
|
||||||
|
// //protocol->translator ( QByteArray() );
|
||||||
|
|
||||||
|
// QObject* obj = metaObj->newInstance ( Q_ARG ( QString, QStringLiteral ( "Rex" ) ), Q_ARG ( QObject*, nullptr ) );
|
||||||
|
// pline() << obj;
|
||||||
|
// QQtProtocol* an = qobject_cast<QQtProtocol*> ( obj );
|
||||||
|
// pline() << an;
|
||||||
|
|
||||||
|
QMap<QByteArray, Constructor*> instance;
|
||||||
|
void* b = pointer_cast<void*> ( &constructorHelper<QQtServer2Protocol> );
|
||||||
|
pline() << b;
|
||||||
|
Constructor* constructor = ( Constructor* ) b;
|
||||||
|
pline() << constructor;
|
||||||
|
instance.insert ( "aaa", constructor );
|
||||||
|
pline() << "ffff";
|
||||||
|
Constructor* func = instance.value ( "aaa" );
|
||||||
|
pline() << func;
|
||||||
|
Constructor* c = pointer_cast<Constructor*> ( &func );
|
||||||
|
|
||||||
|
QQtServer2Protocol* p = ( QQtServer2Protocol* ) ( *c ) ( 0 );
|
||||||
|
pline() << p;
|
||||||
|
p->sendCommand();
|
||||||
|
//p->translator ( QByteArray() );
|
||||||
|
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
QObject* o = QQtObjectFactory::createObject ( "QObject" );
|
||||||
|
pline() << o;
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,11 @@ public:
|
|||||||
}
|
}
|
||||||
void recvCommand2 ( const QQtClient2Message& msg ) {
|
void recvCommand2 ( const QQtClient2Message& msg ) {
|
||||||
//what do you want to do?
|
//what do you want to do?
|
||||||
|
pline() << "dddd";
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendCommand() {
|
||||||
|
pline() << "ffff";
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendCommand1() {
|
void sendCommand1() {
|
||||||
@ -123,7 +128,7 @@ protected:
|
|||||||
pline() << qMsg;
|
pline() << qMsg;
|
||||||
|
|
||||||
switch ( qMsg.cmd() ) {
|
switch ( qMsg.cmd() ) {
|
||||||
case 0x0a://protocol command 1
|
case 0x01://protocol command 1
|
||||||
recvCommand1 ( qMsg );
|
recvCommand1 ( qMsg );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ contains (CONFIG, QQT_SOURCE_BUILDIN) {
|
|||||||
|
|
||||||
#you can open one or more macro to make sdk or link from build.
|
#you can open one or more macro to make sdk or link from build.
|
||||||
#link from sdk is default setting
|
#link from sdk is default setting
|
||||||
#CONFIG += link_from_sdk
|
CONFIG += link_from_sdk
|
||||||
CONFIG += link_from_build
|
#CONFIG += link_from_build
|
||||||
#CONFIG += link_from_qt_lib_path
|
#CONFIG += link_from_qt_lib_path
|
||||||
|
|
||||||
#especially some occations need some sure macro.
|
#especially some occations need some sure macro.
|
||||||
|
@ -60,16 +60,21 @@ public:
|
|||||||
/*
|
/*
|
||||||
* 搜索生成此类对象的函数
|
* 搜索生成此类对象的函数
|
||||||
*/
|
*/
|
||||||
pline() << constructors();
|
//pline() << constructors();
|
||||||
Constructor* constructor = 0;//constructors().value( ( className, 0 );
|
Constructor* constructor = 0;//constructors().value( ( className, 0 );
|
||||||
QMapIterator<QByteArray, Constructor*> itor ( constructors() );
|
QMapIterator<QByteArray, Constructor*> itor ( constructors() );
|
||||||
|
|
||||||
pline() << constructors().isDetached();
|
//pline() << constructors().isDetached();
|
||||||
while ( itor.hasNext() ) {
|
while ( itor.hasNext() ) {
|
||||||
itor.next();
|
itor.next();
|
||||||
pline() << itor.key() << itor.value();
|
//pline() << itor.key() << itor.value();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
/**
|
||||||
|
* @brief 这里发现一个bug,记录
|
||||||
|
* 这里的QByteArray = == 运算全崩溃了。
|
||||||
|
* 经过调查,发现,在跨线程的时候,这个操作无法进行。
|
||||||
|
*/
|
||||||
QByteArray cc;
|
QByteArray cc;
|
||||||
QByteArray dd;
|
QByteArray dd;
|
||||||
cc = itor.key();//?
|
cc = itor.key();//?
|
||||||
@ -80,10 +85,11 @@ public:
|
|||||||
constructor = itor.value();
|
constructor = itor.value();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pline() << itor.key() << itor.value();
|
pline() << className << itor.key() << itor.value();
|
||||||
pline() << ( bool ) ( className == itor.key() );
|
//pline() << ( bool ) ( className == itor.key() );
|
||||||
if ( ( bool ) ( className == itor.key() ) ) {
|
if ( ( bool ) ( className == itor.key() ) ) {
|
||||||
constructor = itor.value();
|
constructor = itor.value();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//pline() << constructor;
|
//pline() << constructor;
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
QQtTcpServer::QQtTcpServer ( QObject* parent ) :
|
QQtTcpServer::QQtTcpServer ( QObject* parent ) :
|
||||||
QTcpServer ( parent )
|
QTcpServer ( parent )
|
||||||
{
|
{
|
||||||
|
connect ( this, SIGNAL ( newConnection() ),
|
||||||
|
this, SLOT ( slotNewConnection() ),
|
||||||
|
Qt::AutoConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
QQtTcpServer::~QQtTcpServer()
|
QQtTcpServer::~QQtTcpServer()
|
||||||
@ -15,6 +18,8 @@ QQtTcpServer::~QQtTcpServer()
|
|||||||
|
|
||||||
void QQtTcpServer::incomingConnection ( qintptr handle )
|
void QQtTcpServer::incomingConnection ( qintptr handle )
|
||||||
{
|
{
|
||||||
|
return QTcpServer::incomingConnection ( handle );
|
||||||
|
|
||||||
QQtTcpClient* clientSocket = new QQtTcpClient ( this );
|
QQtTcpClient* clientSocket = new QQtTcpClient ( this );
|
||||||
clientSocket->setSocketDescriptor ( handle );
|
clientSocket->setSocketDescriptor ( handle );
|
||||||
connect ( clientSocket, SIGNAL ( disconnected() ), clientSocket, SLOT ( deleteLater() ) );
|
connect ( clientSocket, SIGNAL ( disconnected() ), clientSocket, SLOT ( deleteLater() ) );
|
||||||
@ -45,3 +50,19 @@ QQtProtocolManager* QQtTcpServer::installedProtocolManager()
|
|||||||
return m_protocolManager;
|
return m_protocolManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QQtTcpServer::slotNewConnection()
|
||||||
|
{
|
||||||
|
bool has = hasPendingConnections();
|
||||||
|
if ( !has )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QTcpSocket* p = nextPendingConnection();
|
||||||
|
|
||||||
|
QQtTcpClient* clientSocket = new QQtTcpClient ( this );
|
||||||
|
clientSocket->setSocketDescriptor ( p->socketDescriptor() );
|
||||||
|
|
||||||
|
connect ( clientSocket, SIGNAL ( disconnected() ), clientSocket, SLOT ( deleteLater() ) );
|
||||||
|
QQtProtocol* protocolInstance = m_protocolManager->createProtocol();
|
||||||
|
clientSocket->installProtocol ( protocolInstance );
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ public:
|
|||||||
QQtProtocolManager* installedProtocolManager();
|
QQtProtocolManager* installedProtocolManager();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
protected slots:
|
||||||
|
void slotNewConnection();
|
||||||
// QTcpServer interface
|
// QTcpServer interface
|
||||||
protected:
|
protected:
|
||||||
virtual void incomingConnection ( qintptr handle ) override;
|
virtual void incomingConnection ( qintptr handle ) override;
|
||||||
|
0
src/linux_cd_path.sh
Executable file → Normal file
0
src/linux_cd_path.sh
Executable file → Normal file
0
src/linux_cp_files.sh
Executable file → Normal file
0
src/linux_cp_files.sh
Executable file → Normal file
0
src/linux_cur_path.sh
Executable file → Normal file
0
src/linux_cur_path.sh
Executable file → Normal file
@ -14,7 +14,7 @@ class QQTSHARED_EXPORT QQtProtocol : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QQtProtocol ( QObject* parent = 0 );
|
Q_INVOKABLE explicit QQtProtocol ( QObject* parent = 0 );
|
||||||
virtual ~QQtProtocol();
|
virtual ~QQtProtocol();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -22,16 +22,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
qint64 write ( const QByteArray& );
|
qint64 write ( const QByteArray& );
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief 协议处理器
|
|
||||||
* 这个处理器是给QQtTcpSocket用的,不是给客户用的。
|
|
||||||
* @param Qt通讯口readAll()读到的bytes
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
void translator ( const QByteArray& bytes );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 以下函数,用户必须继承下去,重写,need override
|
* 以下函数,用户必须继承下去,重写,need override
|
||||||
*/
|
*/
|
||||||
@ -72,6 +62,16 @@ signals:
|
|||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
void notifyToProtocolManager ( const QQtProtocol* self, const QQtMessage* message );
|
void notifyToProtocolManager ( const QQtProtocol* self, const QQtMessage* message );
|
||||||
|
|
||||||
|
/*以下和用户无关。*/
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief 协议处理器
|
||||||
|
* 这个处理器是给QQtTcpSocket用的,不是给客户用的。
|
||||||
|
* @param Qt通讯口readAll()读到的bytes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void translator ( const QByteArray& bytes );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QQTPROTOCOL_H
|
#endif // QQTPROTOCOL_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user