mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 21:45:34 +08:00
Initial commit
This commit is contained in:
9
blacklib/samples/com_client/CMakeLists.txt
Normal file
9
blacklib/samples/com_client/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
FILE(GLOB sample_com_client_SOURCES *.cpp)
|
||||
SET(sample_com_client_HEADERS client.h)
|
||||
|
||||
QT4_WRAP_CPP(sample_com_client_HEADERS_MOC ${sample_com_client_HEADERS})
|
||||
|
||||
ADD_EXECUTABLE(sample_com_client ${sample_com_client_SOURCES} ${sample_com_client_HEADERS_MOC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(sample_com_client blackmisc ${QT_LIBRARIES})
|
||||
SET_TARGET_PROPERTIES(sample_com_client PROPERTIES PROJECT_LABEL "Samples - Com client")
|
||||
36
blacklib/samples/com_client/client.cpp
Normal file
36
blacklib/samples/com_client/client.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <blackmisc/debug.h>
|
||||
#include "client.h"
|
||||
#include <blackmisc/message.h>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
Client::Client(QObject *parent) : QObject(parent)
|
||||
{
|
||||
connect(&comclient, SIGNAL(doError(QAbstractSocket::SocketError,QString)), this, SLOT(onError(QAbstractSocket::SocketError,QString)));
|
||||
connect(&comclient, SIGNAL(doConnected()), this, SLOT(onClientConnected()));
|
||||
|
||||
QString address = "127.0.0.1";
|
||||
comclient.connectTo(address, 6809);
|
||||
}
|
||||
|
||||
Client::~Client()
|
||||
{
|
||||
}
|
||||
|
||||
void Client::onError(QAbstractSocket::SocketError error, QString message)
|
||||
{
|
||||
bWarning << "Socket error!";
|
||||
}
|
||||
|
||||
void Client::onClientConnected()
|
||||
{
|
||||
QByteArray message_data;
|
||||
QDataStream out(&message_data, QIODevice::WriteOnly);
|
||||
|
||||
IMessage* testmsg = new TestMessage();
|
||||
|
||||
*testmsg >> out;
|
||||
|
||||
comclient.sendMessage(testmsg->getID(), message_data);
|
||||
delete testmsg;
|
||||
}
|
||||
19
blacklib/samples/com_client/client.h
Normal file
19
blacklib/samples/com_client/client.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <blackmisc/message_system.h>
|
||||
#include <blackmisc/com_client.h>
|
||||
|
||||
class Client : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Client(QObject *parent = NULL);
|
||||
~Client();
|
||||
|
||||
protected slots:
|
||||
|
||||
void onError(QAbstractSocket::SocketError,QString);
|
||||
void onClientConnected();
|
||||
|
||||
private:
|
||||
BlackMisc::CComClient comclient;
|
||||
};
|
||||
16
blacklib/samples/com_client/main.cpp
Normal file
16
blacklib/samples/com_client/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <QApplication>
|
||||
|
||||
#include <blackmisc/context.h>
|
||||
#include "client.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BlackMisc::CApplicationContext myApplicationContext;
|
||||
QApplication a(argc, argv);
|
||||
|
||||
Client client;
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user