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 <QQtApplication>
|
||||
#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[] )
|
||||
{
|
||||
QQtApplication a ( argc, argv );
|
||||
|
||||
QQtObjectFactory::registerObject<QObject>();
|
||||
QObject* o = QQtObjectFactory::createObject ( "QObject" );
|
||||
pline() << o;
|
||||
// QObject* o = QQtObjectFactory::createObject ( "QObject" );
|
||||
// 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;
|
||||
w.show();
|
||||
|
||||
QObject* o = QQtObjectFactory::createObject ( "QObject" );
|
||||
pline() << o;
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -77,6 +77,11 @@ public:
|
||||
}
|
||||
void recvCommand2 ( const QQtClient2Message& msg ) {
|
||||
//what do you want to do?
|
||||
pline() << "dddd";
|
||||
}
|
||||
|
||||
void sendCommand() {
|
||||
pline() << "ffff";
|
||||
}
|
||||
|
||||
void sendCommand1() {
|
||||
@ -123,7 +128,7 @@ protected:
|
||||
pline() << qMsg;
|
||||
|
||||
switch ( qMsg.cmd() ) {
|
||||
case 0x0a://protocol command 1
|
||||
case 0x01://protocol command 1
|
||||
recvCommand1 ( qMsg );
|
||||
break;
|
||||
|
||||
|
@ -59,8 +59,8 @@ contains (CONFIG, QQT_SOURCE_BUILDIN) {
|
||||
|
||||
#you can open one or more macro to make sdk or link from build.
|
||||
#link from sdk is default setting
|
||||
#CONFIG += link_from_sdk
|
||||
CONFIG += link_from_build
|
||||
CONFIG += link_from_sdk
|
||||
#CONFIG += link_from_build
|
||||
#CONFIG += link_from_qt_lib_path
|
||||
|
||||
#especially some occations need some sure macro.
|
||||
|
@ -60,16 +60,21 @@ public:
|
||||
/*
|
||||
* 搜索生成此类对象的函数
|
||||
*/
|
||||
pline() << constructors();
|
||||
//pline() << constructors();
|
||||
Constructor* constructor = 0;//constructors().value( ( className, 0 );
|
||||
QMapIterator<QByteArray, Constructor*> itor ( constructors() );
|
||||
|
||||
pline() << constructors().isDetached();
|
||||
//pline() << constructors().isDetached();
|
||||
while ( itor.hasNext() ) {
|
||||
itor.next();
|
||||
pline() << itor.key() << itor.value();
|
||||
//pline() << itor.key() << itor.value();
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief 这里发现一个bug,记录
|
||||
* 这里的QByteArray = == 运算全崩溃了。
|
||||
* 经过调查,发现,在跨线程的时候,这个操作无法进行。
|
||||
*/
|
||||
QByteArray cc;
|
||||
QByteArray dd;
|
||||
cc = itor.key();//?
|
||||
@ -80,10 +85,11 @@ public:
|
||||
constructor = itor.value();
|
||||
#endif
|
||||
|
||||
pline() << itor.key() << itor.value();
|
||||
pline() << ( bool ) ( className == itor.key() );
|
||||
pline() << className << itor.key() << itor.value();
|
||||
//pline() << ( bool ) ( className == itor.key() );
|
||||
if ( ( bool ) ( className == itor.key() ) ) {
|
||||
constructor = itor.value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
//pline() << constructor;
|
||||
|
@ -5,6 +5,9 @@
|
||||
QQtTcpServer::QQtTcpServer ( QObject* parent ) :
|
||||
QTcpServer ( parent )
|
||||
{
|
||||
connect ( this, SIGNAL ( newConnection() ),
|
||||
this, SLOT ( slotNewConnection() ),
|
||||
Qt::AutoConnection );
|
||||
}
|
||||
|
||||
QQtTcpServer::~QQtTcpServer()
|
||||
@ -15,6 +18,8 @@ QQtTcpServer::~QQtTcpServer()
|
||||
|
||||
void QQtTcpServer::incomingConnection ( qintptr handle )
|
||||
{
|
||||
return QTcpServer::incomingConnection ( handle );
|
||||
|
||||
QQtTcpClient* clientSocket = new QQtTcpClient ( this );
|
||||
clientSocket->setSocketDescriptor ( handle );
|
||||
connect ( clientSocket, SIGNAL ( disconnected() ), clientSocket, SLOT ( deleteLater() ) );
|
||||
@ -45,3 +50,19 @@ QQtProtocolManager* QQtTcpServer::installedProtocolManager()
|
||||
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();
|
||||
|
||||
signals:
|
||||
protected slots:
|
||||
void slotNewConnection();
|
||||
// QTcpServer interface
|
||||
protected:
|
||||
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
|
||||
public:
|
||||
explicit QQtProtocol ( QObject* parent = 0 );
|
||||
Q_INVOKABLE explicit QQtProtocol ( QObject* parent = 0 );
|
||||
virtual ~QQtProtocol();
|
||||
|
||||
/*
|
||||
@ -22,16 +22,6 @@ public:
|
||||
*/
|
||||
Q_SIGNALS:
|
||||
qint64 write ( const QByteArray& );
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief 协议处理器
|
||||
* 这个处理器是给QQtTcpSocket用的,不是给客户用的。
|
||||
* @param Qt通讯口readAll()读到的bytes
|
||||
* @return
|
||||
*/
|
||||
void translator ( const QByteArray& bytes );
|
||||
|
||||
/*
|
||||
* 以下函数,用户必须继承下去,重写,need override
|
||||
*/
|
||||
@ -72,6 +62,16 @@ signals:
|
||||
* @param 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user