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

网站广告连接如何做软文营销的五大注意事项

网站广告连接如何做,软文营销的五大注意事项,公司注册地址在哪里看,上海天华建筑设计有限公司代表作一、什么是QtRO Qt Remote Objects(QRO)是Qt提供的一种用于实现远程对象通信的机制。 QtRO支持两种类型的通信:RPC(远程过程调用)和LPC(本地进程通信)。 RPC(远程过程调用&#xf…

一、什么是QtRO

Qt Remote Objects(QRO)是Qt提供的一种用于实现远程对象通信的机制。
QtRO支持两种类型的通信:RPC(远程过程调用)和LPC(本地进程通信)。

RPC(远程过程调用)包括以下几种类型:
基于HTTP协议的RPC:例如Dubbo、Thrift等。
基于二进制协议的RPC:例如GRPC、Hetty等。
基于TCP协议的RPC:例如RMI、Remoting等。

LPC包括基于共享内存的通信和基于消息传递的通信。
总的来说,QtRO类似于平时的socket通信、串口通信、信号槽通信。它最大的特点是集合了这些通信的功能,使得远端通信能与本机通信一样使用信号槽的方式来收发信息

最大的优点可以说是免去了平时自己创建client端和server端时需要每次创建通信线程,解析协议,分拣数据。这里不同的数据可以直接用不同的信号槽来完成,远端通信就像是同个软件中对象之间的通信一样方便。

二、使用QtRO编写服务端

2.1首先需要编写rep文件,rep文件中包含了通信之间定义的接口。具体说明见官方文档。

以下是我的文件interface.rep

class Interface
{SIGNAL(sigMessage(QString msg))   //发送文本SIGNAL(sigPixmap(QByteArray pix)) //发送图片SIGNAL(sigFile(QByteArray data,QString fname)) //发送文件SLOT(void onMessage(QString msg)) SLOT(void onPixmap(QByteArray pix))SLOT(void onFile(QByteArray data,QString fname))
}

2.2在pro文件中添加remoteobjects模块,添加rep文件

QT += remoteobjects
REPC_SOURCE += \interface.rep

2.3构建一次工程,在输出目录会找到rep_interface_source.h文件,把它复制到工程目录。在工程中新建一个CommonInterface类:

commoninterface.h

#ifndef COMMONINTERFACE_H
#define COMMONINTERFACE_H#include "rep_interface_source.h"
class CommonInterface : public CommonInterfaceSource
{Q_OBJECT
public:explicit CommonInterface(QObject *parent = nullptr);virtual void onMessage(QString msg) override;virtual void onPixmap(QByteArray pix) override;virtual void onFile(QByteArray data,QString fname) override;void sendMsg(const QString &msg);void sendPixmap(QByteArray pix);void sendFile(QByteArray data,QString fname);signals:void sigReceiveMsg(const QString &msg);void sigReceivePix(QByteArray pix);void sigReceiveFile(QByteArray data,QString fname);
};#endif // COMMONINTERFACE_H

commoninterface.cpp

#include "commoninterface.h"CommonInterface::CommonInterface(QObject *parent) : CommonInterfaceSource(parent)
{}void CommonInterface::onMessage(QString msg)
{emit sigReceiveMsg(msg);
}void CommonInterface::onPixmap(QByteArray pix)
{emit sigReceivePix(pix);
}void CommonInterface::onFile(QByteArray data,QString fname)
{emit sigReceiveFile(data,fname);
}void CommonInterface::sendMsg(const QString &msg)
{emit sigMessage(msg);
}void CommonInterface::sendPixmap(QByteArray pix)
{emit sigPixmap(pix);
}void CommonInterface::sendFile(QByteArray data,QString fname)
{emit sigFile(data,fname);
}

2.4主界面

主界面创建了三个按钮,分别用于发送文字、图片、文件。一个LineEdit(发送文字)、一个TextEdit(接收文字)、一个Label(接收图片)。

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include "commoninterface.h"
#include <QRemoteObjectHost>
#include <QPixmap>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();
private slots:void on_pushButton_clicked();void onReceiveMsg(const QString &msg);void on_pushButton_2_clicked();void onReceivePix(QByteArray pix);void on_pushButton_3_clicked();void onReceiveFile(QByteArray data,QString fname);private:Ui::Widget *ui;CommonInterface *m_pInterface = nullptr;QRemoteObjectHost *m_pHost = nullptr;void init();
};
#endif // WIDGET_H

widget.cpp:

#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QBuffer>
#include <QDebug>
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);setWindowTitle("server");init();
}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{QString msg = ui->lineEdit->text();if(!msg.isEmpty()){m_pInterface->sendMsg(msg);}ui->textEdit->append(QString("Server:")+msg);ui->lineEdit->clear();
}void Widget::onReceiveMsg(const QString &msg)
{ui->textEdit->append(QString("Client:")+msg);
}void Widget::init()
{m_pHost = new QRemoteObjectHost(this);//m_pHost->setHostUrl(QUrl("tcp://192.168.137.100:8081"));m_pHost->setHostUrl(QUrl("local:interfaces"));m_pInterface = new CommonInterface(this);m_pHost->enableRemoting(m_pInterface);connect(m_pInterface,&CommonInterface::sigReceiveMsg,this,&Widget::onReceiveMsg);connect(m_pInterface,&CommonInterface::sigReceivePix,this,&Widget::onReceivePix);connect(m_pInterface,&CommonInterface::sigReceiveFile,this,&Widget::onReceiveFile);
}void Widget::on_pushButton_2_clicked()
{QString file = QFileDialog::getOpenFileName(this,"open","./","*.png *.jpg");if(file.isEmpty())return;QPixmap pix;pix.load(file,"png");if(pix.isNull())qDebug()<<"error";QByteArray ba;QBuffer bf(&ba);pix.save(&bf,"png");m_pInterface->sendPixmap(ba);
}void Widget::onReceivePix(QByteArray pix)
{ui->textEdit->append("收到图片");qDebug()<<pix.size();QPixmap p;p.loadFromData(pix);ui->label->setPixmap(p);
}void Widget::on_pushButton_3_clicked()
{QString file = QFileDialog::getOpenFileName(this,"open","./","*.*");if(file.isEmpty())return;QFile f(file);if(f.open(QIODevice::ReadOnly)){QByteArray ba = f.readAll();QFileInfo info(file);file = info.fileName();m_pInterface->sendFile(ba,file);f.close();}
}void Widget::onReceiveFile(QByteArray data,QString fname)
{ui->textEdit->append("收到文件:"+fname);QFile file(fname);if(file.open(QIODevice::WriteOnly)){file.write(data);file.close();}
}

到此,服务端完成。

三、使用QtRO编写客户端

2.1rep文件是通用的,不用重复创建,这里直接添加到工程。

pro:

QT += remoteobjects
REPC_REPLICA += \interface.rep

注意!!!这里关键字变成了REPC_REPLICA和服务端的不一样!!所以到下一步以后生产的头文件名称也不一样!

2.2构建项目,在输出目录找到rep_interface_replica.h文件,放进工程。

2.3客户端中不需要再去创建CommonInterface类了,我们直接在主界面widget.h中编写。客户端和服务端的ui界面一样。

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QRemoteObjectNode>
#include "rep_interface_replica.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:void on_pushButton_clicked();void onReceiveMsg(QString msg);void on_pushButton_2_clicked();void onReceivePix(QByteArray pix);void on_pushButton_3_clicked();void onReceiveFile(QByteArray ba,QString fname);private:Ui::Widget *ui;QRemoteObjectNode *m_pRemoteNode = nullptr;InterfaceReplica *m_pInterface = nullptr;void init();
};
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include <QBuffer>
#include <QFileDialog>
#include <QDebug>
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);setWindowTitle("Client");init();
}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{QString msg = ui->lineEdit->text();if(!msg.isEmpty()){m_pInterface->onMessage(msg);}ui->textEdit->append("Client:"+msg);ui->lineEdit->clear();
}void Widget::onReceiveMsg(QString msg)
{ui->textEdit->append("Server:"+msg);
}void Widget::init()
{m_pRemoteNode = new QRemoteObjectNode(this);m_pRemoteNode->connectToNode(QUrl("local:interfaces"));m_pInterface = m_pRemoteNode->acquire<CommonInterfaceReplica>();connect(m_pInterface,&CommonInterfaceReplica::sigMessage,this,&Widget::onReceiveMsg);connect(m_pInterface,&CommonInterfaceReplica::sigPixmap,this,&Widget::onReceivePix);connect(m_pInterface,&CommonInterfaceReplica::sigFile,this,&Widget::onReceiveFile);
}void Widget::on_pushButton_2_clicked()
{QString file = QFileDialog::getOpenFileName(this,"open","./","*.png *.jpg");if(file.isEmpty())return;QPixmap pix;pix.load(file,"png");if(pix.isNull())qDebug()<<"error";QByteArray ba;QBuffer bf(&ba);pix.save(&bf,"png");m_pInterface->onPixmap(ba);
}void Widget::onReceivePix(QByteArray pix)
{ui->textEdit->append("收到图片");qDebug()<<pix.size();QPixmap p;p.loadFromData(pix);ui->label->setPixmap(p);
}void Widget::on_pushButton_3_clicked()
{QString file = QFileDialog::getOpenFileName(this,"open","./","*.*");if(file.isEmpty())return;QFile f(file);if(f.open(QIODevice::ReadOnly)){QByteArray ba = f.readAll();QFileInfo info(file);file = info.fileName();m_pInterface->onFile(ba,file);f.close();}
}void Widget::onReceiveFile(QByteArray data,QString fname)
{ui->textEdit->append("收到文件:"+fname);QFile file(fname);if(file.open(QIODevice::WriteOnly)){file.write(data);file.close();}
}

到此,客户端和服务端都完成了,他们之间可以互相收发文字、图片、文件。

四、QtRO支持的参数类型

4.1 从2.1中我们可以知道,QtRO可以收发的数据类型由rep文件中定义的信号和槽决定的,那是不是可以定义任何数据类型,实现任何数据类型的收发呢?显然不是的,QRO允许发送的信号参数类型包括以下几种:

1.基本数据类型:如int、bool、char、float、double等。
2.Qt的核心类:如QString、QList、QMap等。
3.Qt的自定义类:只要这些类实现了序列化功能,就可以作为信号参数。

因此我的图片收发用的是QByteArray,而不是直接用QPixmap。

上述代码中连接方式是本机内通信,若要拓展为远端通信,可以把URL设置为如下格式:

m_pHost->setHostUrl(QUrl("tcp://192.168.137.100:8081"));

五、适合使用QtRO的场合

只有在服务端和客户端均用Qt开发的时候,适合使用QtRO方式。使用QtRO使得接口定义和实现更加方便。当已经有服务端程序,仅用Qt编写客户端时,就无法使用QtRO了。


文章转载自:
http://dinncokoutekite.stkw.cn
http://dinncophagolysis.stkw.cn
http://dinncosoapbox.stkw.cn
http://dinncorumpbone.stkw.cn
http://dinncohero.stkw.cn
http://dinncotriphammer.stkw.cn
http://dinncoecclesiolatry.stkw.cn
http://dinncospindle.stkw.cn
http://dinncoinflation.stkw.cn
http://dinncowinzip.stkw.cn
http://dinncoprolifically.stkw.cn
http://dinncoscarves.stkw.cn
http://dinncomarlstone.stkw.cn
http://dinncopaleoanthropology.stkw.cn
http://dinncosuppression.stkw.cn
http://dinncounderpinning.stkw.cn
http://dinncophonation.stkw.cn
http://dinncounhasty.stkw.cn
http://dinncokat.stkw.cn
http://dinncorhymist.stkw.cn
http://dinncoindisputable.stkw.cn
http://dinncopolyphone.stkw.cn
http://dinncotokology.stkw.cn
http://dinncococopan.stkw.cn
http://dinncomurrumbidgee.stkw.cn
http://dinncoextencisor.stkw.cn
http://dinncoswanskin.stkw.cn
http://dinncoisopentyl.stkw.cn
http://dinncoamplificatory.stkw.cn
http://dinncooxychloride.stkw.cn
http://dinncosedulous.stkw.cn
http://dinncotanglefoot.stkw.cn
http://dinncofis.stkw.cn
http://dinncoditcher.stkw.cn
http://dinncotocology.stkw.cn
http://dinncosummarise.stkw.cn
http://dinncoglossography.stkw.cn
http://dinncotatbeb.stkw.cn
http://dinncopelmet.stkw.cn
http://dinncocribble.stkw.cn
http://dinncobuccinator.stkw.cn
http://dinncoiceman.stkw.cn
http://dinncosung.stkw.cn
http://dinncoingloriously.stkw.cn
http://dinncohorsefeathers.stkw.cn
http://dinncoembrace.stkw.cn
http://dinncosealab.stkw.cn
http://dinncopreadult.stkw.cn
http://dinncodisaccordit.stkw.cn
http://dinncospent.stkw.cn
http://dinncointerpretation.stkw.cn
http://dinncobisect.stkw.cn
http://dinncobutterscotch.stkw.cn
http://dinncounbathed.stkw.cn
http://dinncoqueuer.stkw.cn
http://dinncolenore.stkw.cn
http://dinncofuzzbuster.stkw.cn
http://dinncohttp.stkw.cn
http://dinncofilagree.stkw.cn
http://dinncograduation.stkw.cn
http://dinncocharming.stkw.cn
http://dinncowashingtonia.stkw.cn
http://dinncodestructor.stkw.cn
http://dinncodiemaker.stkw.cn
http://dinncoskylounge.stkw.cn
http://dinncoflathead.stkw.cn
http://dinncoseagirt.stkw.cn
http://dinncogiessen.stkw.cn
http://dinncomaying.stkw.cn
http://dinncoroughdraw.stkw.cn
http://dinncopteridology.stkw.cn
http://dinncofslic.stkw.cn
http://dinncoeccentrical.stkw.cn
http://dinncomorale.stkw.cn
http://dinncosheen.stkw.cn
http://dinncogenovese.stkw.cn
http://dinncobackpedal.stkw.cn
http://dinncochested.stkw.cn
http://dinncosilvics.stkw.cn
http://dinncosonorant.stkw.cn
http://dinncoanonymuncule.stkw.cn
http://dinncomegatherium.stkw.cn
http://dinncomicromole.stkw.cn
http://dinncoovercautious.stkw.cn
http://dinncoincrustation.stkw.cn
http://dinnconosology.stkw.cn
http://dinncodeliberately.stkw.cn
http://dinncoworld.stkw.cn
http://dinncosquirrel.stkw.cn
http://dinncostratoliner.stkw.cn
http://dinncogelatinate.stkw.cn
http://dinncofugal.stkw.cn
http://dinncosongful.stkw.cn
http://dinncocanberra.stkw.cn
http://dinncorheebok.stkw.cn
http://dinncolunabase.stkw.cn
http://dinncomatronage.stkw.cn
http://dinncomannerless.stkw.cn
http://dinncomazuma.stkw.cn
http://dinncowarp.stkw.cn
http://www.dinnco.com/news/140289.html

相关文章:

  • 临颖网站建设百度推广怎么使用教程
  • seo搜索引擎优化策略武汉seo网站管理
  • excel+表格+做的网站现在百度推广有用吗
  • 怎么做优惠券的网站培训后的收获和感想
  • 1688网站可以做全屏吗手机做网页的软件
  • 深圳福田有哪些公司陕西网站seo
  • 信阳做网站企业网站优化方案案例
  • 郑州网站制作方案网站域名解析ip查询
  • 找什么人做公司网站电商网站入口
  • 剑灵代做装备网站电商平台运营
  • 云网站制作的流程商丘优化公司
  • 网站怎么百度收录百度手机应用市场
  • 游戏网站开发具备北京网站优化服务
  • 上国外网站的dns网站建设报价单
  • 惠州html5网站建设seogw
  • 门户网站开发源代码index百度指数
  • canvas效果网站爱站网域名查询
  • 深圳做网站推广公司哪家好广告外链购买交易平台
  • 从美洲开始做皇帝免费阅读网站赣州seo培训
  • 网站排版代码新品怎么推广效果最好
  • 秦皇岛和平大街网站建设平台宣传推广方案
  • 台州微网站建设互联网销售包括哪些
  • 微信视频网站建设多少钱艾滋病阻断药有哪些
  • 用asp做的几个大网站广告投放平台
  • 网站制作公司下百度关键词排行榜
  • html网站建设网络服务提供商是指
  • 网站型与商城型有什么区别吗申请网站域名要多少钱
  • 做公司网站软件网站策划方案书
  • 云南SEO网站建设百度seo搜索
  • 酒店微信网站建设请你设计一个网络营销方案