当前位置: 首页 > news >正文

免费企业网站源代码深圳高端女装品牌排行榜

免费企业网站源代码,深圳高端女装品牌排行榜,公司付网站会员费科目怎么做,青岛房产网二手房最新信息QT项目_RPC(进程间通讯) 前言#xff1a; 两个进程间通信、或是说两个应用程序之间通讯。实际情况是在QT开发的一个项目中#xff0c;里面包含两个子程序#xff0c;子程序有单独的界面和应用逻辑#xff0c;这两个子程序跑起来之后需要一些数据的交互#xff0c;例如 两个进程间通信、或是说两个应用程序之间通讯。实际情况是在QT开发的一个项目中里面包含两个子程序子程序有单独的界面和应用逻辑这两个子程序跑起来之后需要一些数据的交互例如一个程序是用户界面和用户程序另一个程序时OSD菜单 注意RPC通讯传输的数据类型有bool、int和std::string(QString不行) 效果演示 1、移植RCP源码到自己工程 ①移植RPC说白了就是两个文件夹里面有N多个源文件直接复制过来直接用需要自行修改.pro文件以便加入编译 # rest_rpc INCLUDEPATH $$PWD/msgpack DEPENDPATH $$PWD/msgpack②工程目录 2、源码展示 test_rpc.pro TEMPLATE subdirsSUBDIRS \apply \layer apply/apply.pro QT quick \widgetsCONFIG c11# The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES QT_DISABLE_DEPRECATED_BEFORE0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES \main.cpp \mainwidget.cpp \rpc/MessageTip.cpp \rpc/RPCClient.cpp \rpc/RPCServer.cppRESOURCES qml.qrc# Additional import path used to resolve QML modules in Qt Creators code model QML_IMPORT_PATH # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH # Default rules for deployment. qnx: target.path /tmp/$${TARGET}/bin else: unix:!android: target.path /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS target# rest_rpc INCLUDEPATH $$PWD/msgpack DEPENDPATH $$PWD/msgpackHEADERS \mainwidget.h \rpc/MessageTip.h \rpc/RPCClient.h \rpc/RPCServer.h apply/Headers/rpc/MessageTip.h #ifndef MESSAGETIP_H #define MESSAGETIP_H#include qstring.hnamespace MessageTip {void onApplyvalueChanged(int value);void onApplystringChanged(std::string value); }#endif // MESSAGETIP_H apply/Headers/rpc/RPCClient.h #ifndef RPCCLIENT_H #define RPCCLIENT_H#include rest_rpc/rpc_client.hppclass RPCClient { public:RPCClient();static RPCClient *get_instance(){static RPCClient manage;return manage;}/*** brief 尝试连接RPC Server* return true 连接成功false 连接失败*/void tryConnect();rest_rpc::rpc_client *getSocketObject();private:rest_rpc::rpc_client *m_pClient nullptr; };#endif // RPCCLIENT_H apply/Headers/rpc/RPCServer.h #ifndef RPCSERVER_H #define RPCSERVER_H#include qstring.h #include rest_rpc/rpc_server.husing namespace rest_rpc; using namespace rpc_service;class RPCServer { public:RPCServer();void setApplyvalue(rpc_conn conn , int value);void setApplystring(rpc_conn conn , std::string value); };#endif // RPCSERVER_H apply/Headers/mainwidget.h #ifndef MAINWIDGET_H #define MAINWIDGET_H#include QObject #include QWidget #include QQmlComponent #include QQmlApplicationEngine #include QQuickItem #include rpc/RPCServer.hclass MainWidget : public QObject {Q_OBJECT public:MainWidget();protected slots:void onClickPageNo(bool enable);void onApplyvalueChanged(int value);void onApplystringChanged(QString value);private:QQuickItem *m_applyItem nullptr;QObject *m_applyObject nullptr;RPCServer *m_pRPCServer nullptr; };#endif // MAINWIDGET_H apply/Sources/rpc/MessageTip.cpp #include MessageTip.h #include RPCClient.h #include qdebug.hvoid MessageTip::onApplyvalueChanged(int value) {try {RPCClient::get_instance()-getSocketObject()-callvoid(MessageTip::layervalueChanged, value);} catch (const std::exception e) {qDebug() Exception {}, e.what();} }void MessageTip::onApplystringChanged(std::string value) {try {RPCClient::get_instance()-getSocketObject()-callvoid(MessageTip::layerstringChanged, value);} catch (const std::exception e) {qDebug() Exception {}, e.what();} } apply/Sources/rpc/RPCClient.cpp #include RPCClient.h #include QtDebugRPCClient::RPCClient() {}void RPCClient::tryConnect() {m_pClient new rest_rpc::rpc_client(127.0.0.1, 9000);m_pClient-enable_auto_reconnect(true);m_pClient-connect();std::thread([] {while (true){if (m_pClient-has_connected()) {qDebug() apply RPC connect success;break;} else {qDebug() apply RPC connect fail;std::this_thread::sleep_for(std::chrono::milliseconds(500));}}}).detach(); }rest_rpc::rpc_client *RPCClient::getSocketObject() {return m_pClient; } apply/Sources/rpc/RPCServer.cpp #include RPCServer.h #include qdebug.hRPCServer::RPCServer() {std::thread([] {rpc_server server(9001, std::thread::hardware_concurrency());server.register_handler(MessageTip::setApplyvalue, RPCServer::setApplyvalue, this);server.register_handler(MessageTip::setApplystring, RPCServer::setApplystring, this);server.run();}).detach(); }void RPCServer::setApplyvalue(rpc_conn conn , int value) {//todoqDebug() apply recv : value; }void RPCServer::setApplystring(rpc_conn conn , std::string value) {//todoqDebug() apply recv : QString::fromStdString(value); } apply/Sources/main.cpp #include QGuiApplication #include QQmlApplicationEngine #include mainwidget.h #include qdebug.h #include qthread.hint main(int argc, char *argv[]) {QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);QGuiApplication app(argc, argv);// QQmlApplicationEngine engine; // const QUrl url(QStringLiteral(qrc:/main.qml)); // QObject::connect(engine, QQmlApplicationEngine::objectCreated, // app, [url](QObject * obj, const QUrl objUrl) { // if (!obj url objUrl) { // QCoreApplication::exit(-1); // } // }, Qt::QueuedConnection); // engine.load(url);MainWidget mainwidget;return app.exec(); } apply/Sources/mainwidget.cpp #include mainwidget.h #include qdebug.h #include rpc/RPCClient.h #include rpc/MessageTip.h #include QProcessMainWidget::MainWidget() {QQmlApplicationEngine *m_pEngine new QQmlApplicationEngine;QQmlComponent component(m_pEngine, QUrl(QStringLiteral(qrc:/main.qml)));QObject *mainObject component.create();if (mainObject nullptr) {qDebug() mainObject fail;return;}QListQObject * objectList mainObject-findChildrenQObject *(mybutton);if (objectList.isEmpty()) {qDebug() mybutton failed\n;return;}m_applyObject objectList.last();connect(m_applyObject, SIGNAL(applyvalueChanged(int)), this, SLOT(onApplyvalueChanged(int)));connect(m_applyObject, SIGNAL(applystringChanged(QString)), this, SLOT(onApplystringChanged(QString)));connect(mainObject, SIGNAL(window_interface(bool)), this, SLOT(onClickPageNo(bool)));m_pRPCServer new RPCServer();RPCClient::get_instance()-tryConnect(); }void MainWidget::onClickPageNo(bool enable) {QProcess *process new QProcess();process-start(/home/zhou/work/test/build-test_rpc-Desktop_Qt_5_14_2_GCC_64bit-Debug/layer/layer); }void MainWidget::onApplyvalueChanged(int value) {qDebug() onApplyvalueChanged value;MessageTip::onApplyvalueChanged(value); }void MainWidget::onApplystringChanged(QString value) {qDebug() onApplystringChanged value;MessageTip::onApplystringChanged(std::string(value.toLocal8Bit())); } apply/main.qml import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12Window {visible: truewidth: 640height: 480objectName: apply_windowtitle: qsTr(Hello apply)signal window_interface(bool enable)Column{anchors.fill: parentspacing: 20Button{width: 140height: 50text: 开启界面2onClicked: {window_interface(true)}}Mybutton{width: 140height: 300}} } apply/Mybutton.qml import QtQuick 2.0 import QtQuick.Controls 2.12Item {objectName: mybuttonsignal applyvalueChanged(int value)signal applystringChanged(string value)Column{spacing: 10Button{objectName: buttonwidth: 140height: 50text: send1onClicked: {applyvalueChanged(1)}}Button{width: 140height: 50text: send2onClicked: {applyvalueChanged(2)}}Button{width: 140height: 50text: 验证stringonClicked: {applystringChanged({\name\:\lili\,\age\:24,\class\:6})}}} } layer.pro QT quick QT widgetsCONFIG c11# The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES QT_DISABLE_DEPRECATED_BEFORE0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES \main.cpp \mainwidget.cpp \rpc/MessageTip.cpp \rpc/RPCClient.cpp \rpc/RPCServer.cppRESOURCES qml.qrc# Additional import path used to resolve QML modules in Qt Creators code model QML_IMPORT_PATH # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH # Default rules for deployment. qnx: target.path /tmp/$${TARGET}/bin else: unix:!android: target.path /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS target# rest_rpc INCLUDEPATH $$PWD/msgpack DEPENDPATH $$PWD/msgpackHEADERS \mainwidget.h \rpc/MessageTip.h \rpc/RPCClient.h \rpc/RPCServer.h layer/Headers/rpc/MessageTip.h #ifndef MESSAGETIP_H #define MESSAGETIP_H#include qstring.hnamespace MessageTip {void setApplyvalue(int value);void setApplystring(std::string value); }#endif // MESSAGETIP_H layer/Headers/rpc/RPCClient.h #ifndef RPCCLIENT_H #define RPCCLIENT_H#include rest_rpc/rpc_client.hppclass RPCClient { public:RPCClient();static RPCClient *get_instance(){static RPCClient layer_manage;return layer_manage;}/*** brief 尝试连接RPC Server* return true 连接成功false 连接失败*/void tryConnect();rest_rpc::rpc_client *getSocketObject();private:rest_rpc::rpc_client *m_pClient nullptr; };#endif // RPCCLIENT_H layer/Headers/rpc/RPCServer.h #ifndef RPCSERVER_H #define RPCSERVER_H#include QtDebug #include QThread #include QObject #include QQuickItem#include rest_rpc/rpc_server.h using namespace rest_rpc; using namespace rpc_service;class RPCServer : public QObject {Q_OBJECT public:explicit RPCServer(QObject *parent nullptr);void layervalueChanged(rpc_conn conn , int value);void layerstringChanged(rpc_conn conn , std::string value);protected:signals:private:QObject *m_pMainObject nullptr;QQuickItem *m_pOSDAreaItem nullptr; };#endif // RPCSERVER_H layer/Headers/mainwidget.h #ifndef MAINWIDGET_H #define MAINWIDGET_H#include QObject #include QQmlComponent #include QQmlApplicationEngine #include QQuickItem #include rpc/RPCServer.hclass mainwidget : public QObject {Q_OBJECT public:mainwidget();private:RPCServer *m_pRPCServer nullptr; };#endif // MAINWIDGET_H layer/Sources/rpc/MessageTip.cpp #include MessageTip.h #include RPCClient.h #include QtDebugvoid MessageTip::setApplyvalue(int value) {try {return RPCClient::get_instance()-getSocketObject()-callvoid(MessageTip::setApplyvalue, value);} catch (const std::exception e) {qDebug() setImageRotate exception e.what();} }void MessageTip::setApplystring(std::string value) {try {return RPCClient::get_instance()-getSocketObject()-callvoid(MessageTip::setApplystring, value);} catch (const std::exception e) {qDebug() setImageRotate exception e.what();} } layer/Sources/rpc/RPCClient.cpp #include RPCClient.h #include QtDebugRPCClient::RPCClient() {}void RPCClient::tryConnect() { //#if defined(__x86_64) // m_pClient new rest_rpc::rpc_client(192.168.31.95, 9001); //#elsem_pClient new rest_rpc::rpc_client(127.0.0.1, 9001); //#endifm_pClient-enable_auto_heartbeat(true);m_pClient-connect();std::thread([] {while (true){qDebug() layer RPC connect fail;if (m_pClient-has_connected()) {qDebug() layer RPC connect success;break;} else {std::this_thread::sleep_for(std::chrono::milliseconds(500));qDebug() layer RPC connect fail;}}}).detach(); }rest_rpc::rpc_client *RPCClient::getSocketObject() {return m_pClient; } layer/Sources/rpc/RPCServer.cpp #include RPCServer.h #include rpc/MessageTip.hRPCServer::RPCServer(QObject *parent) : QObject(parent) {QThread::create([] {rpc_server server(9000, std::thread::hardware_concurrency());server.register_handler(MessageTip::layervalueChanged, RPCServer::layervalueChanged, this);server.register_handler(MessageTip::layerstringChanged, RPCServer::layerstringChanged, this);server.run();})-start();qDebug() start rpc server; }void RPCServer::layervalueChanged(rpc_conn conn , int value) {//todoMessageTip::setApplyvalue(value);qDebug() APPLY SEND : value; }void RPCServer::layerstringChanged(rpc_conn conn , std::string value) {//todoMessageTip::setApplystring(value);qDebug() APPLY SEND : QString::fromStdString(value); } layer/Sources/main.cpp #include QGuiApplication #include QQmlApplicationEngine #include qdebug.h #include mainwidget.hint main(int argc, char *argv[]) {QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);QGuiApplication app(argc, argv);// QQmlApplicationEngine engine; // const QUrl url(QStringLiteral(qrc:/main.qml)); // QObject::connect(engine, QQmlApplicationEngine::objectCreated, // app, [url](QObject * obj, const QUrl objUrl) { // if (!obj url objUrl) { // QCoreApplication::exit(-1); // } // }, Qt::QueuedConnection); // engine.load(url);mainwidget mainwidget;return app.exec(); } layer/Sources/mainwidget.cpp #include mainwidget.h #include rpc/RPCClient.hmainwidget::mainwidget() {QQmlApplicationEngine *m_pEngine new QQmlApplicationEngine;QQmlComponent component(m_pEngine, QUrl(QStringLiteral(qrc:/main.qml)));QObject *mainObject component.create();if (mainObject nullptr) {qDebug() mainObject fail;return;}m_pRPCServer new RPCServer();RPCClient::get_instance()-tryConnect(); } layer/main.qml import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12Window {visible: truewidth: 640height: 480title: qsTr(Hello layer)Column{anchors.fill: parentspacing: 20Button{width: 140height: 50text: layer }Button{width: 140height: 50text: layer -}} }
http://www.w-s-a.com/news/5486/

相关文章:

  • 摄影作品投稿网站目前最好的引流推广方法
  • 资源站源码永久dede网站搬家 空间转移的方法
  • 网站建设销售的技巧话语it培训机构
  • 自建本地网站服务器wordpress南充房产网最新楼盘最近房价
  • 郑州代做网站天津哪里能做网站
  • 网站如何做排名网站建设项目的工作分解
  • 洛阳网络建站公司网站开发主流语言
  • 广州各区正在进一步优化以下措施seo值是什么意思
  • 滨州建网站公司京东云 wordpress
  • 网站视频背景怎么做免费的网络推广有哪些
  • 申请网站怎样申请广西壮族自治区专升本业务系统
  • 写作网站哪个网站做ic外单好
  • 苏州和城乡建设局网站撸撸撸做最好的导航网站
  • 网站被同行抄袭怎么办深圳中装建设集团
  • 建站及推广瓦房店 网站建设
  • 怎么查网站是在哪里备案的广州电力建设有限公司网站
  • 做网站自己申请域名还是对方wordpress管理地址
  • 专门做二手书网站或appwordpress首页显示特定分类文章
  • 无锡网站设计厂家一建十个专业含金量排名
  • 网站刷链接怎么做成都高度网站技术建设公司
  • flash网站模板怎么用xml网站地图生成
  • 英文网站优化群晖wordpress中文
  • saas建站平台源码济南品牌网站建设公司
  • 网站建设一般是用哪个软件网站百度
  • 企业建站的作用是什么南宁公司网站开发
  • 厦门网站建设及维护门户网站开发视频教学
  • 可以做兼职的网站有哪些自动点击器永久免费版
  • 建购物网站怎么建呀网站怎么做中英文交互
  • 网站建设费用计入无形资产做网站用的主机
  • 佛山企业网站建设平台沈阳网站建设培训班