Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Network forwarding by Qt

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to achieve network forwarding in Qt". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. Preface

What is the function meaning of network forwarding in this system? in fact, it is to package and send all the data of the local collection equipment to the designated network address, which is in the form of UDP by default and has little connection overhead. I also see a lot of configuration software with this function. In fact, there are many existing gas detection companies, environmental monitoring companies and so on. Are using a large number of configuration software to make a simple system for customers to use. This network forwarding is very useful, for example, it can be forwarded to clients in multiple networks, cascaded layer by layer, generally speaking, the device acquisition end is used as the sender, and the other client end is used as the receiver. The limitation that device collection can only be exclusively on one client is eliminated, and the real-time data can be seen in many places.

The function of network forwarding is generally made one-way. The sender is responsible for sending and the receiver is responsible for receiving data parsing processing. As long as the data source of the device is changed into a network, the parsing method is completely the same. In fact, they all share a common parsing class. The abstract common data parsing class, no matter whether your data is from serial port or tcp or udp, can be parsed and stored after getting the data. If you add other specific field parsing later, as long as you change a class, instead of writing multiple classes to parse separately, in fact, the serial port is also good, the network is also, are all data streams, the only difference is that the pipeline is different, it is OK to distinguish the different ones according to type, and the receiving and parsing of the data are exactly the same. The temperature and humidity monitoring project was written around 2014. At that time, the stupid serial port wrote a class, the tcp client wrote a class, the tcp server wrote a class, and udp wrote a class. Later, it was found that once a function for setting parameters was added, the same function would be added in many places, which was absolutely unnecessary.

II. Functional features

Collect data port, support serial port + network port, serial port support free setting of serial number + baud rate, network support free setting of IP address + communication port, each port supports collection cycle, default one address per second, support setting communication timeout times, default 3 times, support maximum reconnection time, used to re-read offline devices.

Controller information, you can add the controller name, select the controller address + controller model, and set the number of detectors under the controller.

Detector information, can add tag, free to choose detector type, gas type, gas symbol, high reported value, low reported value, buffer value, clear zero value, whether enabled, alarm sound, background map, storage cycle, numerical conversion decimal places, alarm delay time, alarm type (HH,LL,HL) and so on.

Controller model + detector type + gas type + gas symbol, all can be configured freely.

Maps can be imported and deleted, and all detectors can be dragged and saved freely.

Port information + controller information + detector information, support import and export + export to excel+ printing.

Run record + alarm record + user record, support multi-condition combination query, such as time period + controller + detector, etc., all records can be exported to excel+ printing.

Records exported to excel support all versions of table files such as excel+wps and do not rely on software such as excel.

You can delete data within a specified time range, support automatic cleaning of early data, and set the maximum number of saved records.

Support alarm short message forwarding, support multiple receiving mobile phone numbers, you can set the sending interval, such as instant sending or sending all alarm messages once every 6 hours, the text message content is too long, automatically split multiple text messages.

Support alarm email forwarding, support multiple receiving mailboxes, can set sending interval, such as immediate sending or sending all alarm messages once every 6 hours, support attachment sending.

Overreport color + underreport color + normal color + 0 value color + curve background + curve color, etc., are free to choose.

The Chinese title + English title + logo path + copyright of the software can be set freely.

Provide switch settings for boot operation + alarm sound + automatic login + remember password and so on.

Alarm sound can be set to play the number of times, the interface provides 17 kinds of skin file selection.

Cloud data synchronization is supported, and the information of cloud database can be set, such as database name, user name + password, etc.

Support network forwarding and network reception, after the network reception is turned on, the software receives data from udp for analysis. Network forwarding supports multiple target IP, so it realizes the software of local collection, and freely transfers the data to the client to view the detector data at any time.

Automatically remember the user's last stay in the interface + other information, restart and apply automatically.

The alarm automatically switches to the corresponding map, and the detector button flashes.

Double-click the detector icon to control it back.

Support user rights management, administrator + operator two categories, user login + user exit, can remember the password and automatic login, more than three error messages and close the program.

Support four monitoring modes, equipment panel monitoring + map monitoring + table data monitoring + curve data monitoring, free to switch, four synchronous applications.

Support alarm relay linkage, a tag can link multiple modules and relay numbers across serial ports, and support many-to-many.

The local data store supports sqlite+mysql and remote data synchronization to the cloud database. Automatically reconnect.

The data collected by the local device is uploaded to the cloud in real time so that it can be extracted by other methods such as APP or web.

Two kinds of data sources are supported, one is serial port and network to collect equipment data through protocol, the other is database collection. The database acquisition mode can be used as a general system.

Comes with a device simulation tool that supports 16 device data simulations, as well as database data simulations to test data when there is no device.

The default communication protocol uses modbus protocol, and later increases the support of mqtt and other Internet of things protocols to make a general system.

Supports all windows operating systems + linux operating systems and other operating systems.

Third, effect picture

Core code # include "udpsend.h" # include "quiwidget.h" # include "dbhelper.h" QScopedPointer UdpSend::self;UdpSend * UdpSend::Instance () {if (self.isNull ()) {static QMutex mutex; QMutexLocker locker (& mutex); if (self.isNull ()) {self.reset (new UdpSend);}} return self.data () } UdpSend::UdpSend (QObject * parent): QObject (parent) {udpSocket = new QUdpSocket (this);} UdpSend::~UdpSend () {} void UdpSend::sendData (const QString & portName, quint8 addr, const QByteArray & data) {if (! App::UseNetSend) {return;} / / take out ip and port QList ips; QList ports; QStringList list = App::NetSendInfo.split (";") Foreach (QString str, list) {if (str.contains (":")) {QStringList temp = str.split (":"); ips writeDatagram (buffer.toUtf8 (), QHostAddress (ips.at (I)), ports.at (I)); udpSocket- > flush () } void UdpSend::start () {DBHelper::addUserLog ("device reporting", "Network forwarding start Service");} void UdpSend::stop () {DBHelper::addUserLog ("device reporting", "Network forwarding stop Service");} void UdpSend::sendInfo () {if (! App::UseNetSend) {return } / / send port information table + device information table + detector information table QStringList portInfo, deviceInfo, nodeInfo; for (int I = 0; I < DBData::PortInfo_Count; iTunes +) {QStringList list; list

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 294

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report