The article directories

  • QT implements message and file interaction between the client and server
    • Platform environment
    • Database selection and installation
    • Cross-compile toolchain GCC installation
    • Database creation data
    • Qt development environment building
    • The Web implementation
      • TCP network communication flow
      • Loongson server terminal server and client running
    • To achieve server-side and client-side text data interaction
      • The server establishes communication
      • Customer service establishes communication

Platform environment

Loongson Qt5.6.1 visual programming development environment MySQL5.5.40 database

Database selection and installation

Decompress mysql-5.5.40 to the mysql SERVER folder, rename it mysql-5.5, modify the information in the my-default.ini file, and configure environment variables. Finally, run the MySQL command “MySQL -u root -p” to access the database. To ensure the privacy of database information, you need to add the root password for the database. Run the MySQL command “set password for root@localhost=password(‘ XXXXXX ‘)” to change the root password to XXXXXX.

Cross-compile toolchain GCC installation

(1) Create the corresponding directory to store the compiler; Use the mkdir /wyj/mipsel command to create a folder with the path /wyj/mipsel to store all the tools used by the mipsel-linux-gcc compiler. (2) Decompress the compiler installation package; Go to the /wyj/mipsel folder and unzip the cross-build tool with tar JXVF mipsel-linux-gcc-4.9.3.tar.xz. (3) Set the value of environment variable PATH; Set the environment variable PATH with $export PATH=/wyj/mipsel/mipsel-linux-gcc-4.9.3/bin:$PATH. (4) Test whether the cross-compiler is installed smoothly. Write mipsel-linux-gcc-v in the terminal of loongson server. If the terminal outputs the installation version number and configuration information of the cross-compiler, it indicates that the cross-compilation has been successfully installed.

Database creation data

MySQL > create database XXX; MySQL > create database XXX; Create XXX information (id int, name text, sno text, KFH text, kNO text, Select id, name, SNO, KFH, kNO, sDEPT, and sDEPT from sDEPT. Insert into information values(*,*,*,*,*,*) to add data to the information table.

Qt development environment building

(1) Download the Qt development integration environment, decompress it and enter the directory;

$tar ZXVF qt-everywhere-opensource-src-5.6.1.tar.gz $CD qt-everywhere-opensource-src-5.6.1/Copy the code

/usr/local/ qt-5.6.1 /usr/local/ qt-5.6.1 /usr/local/ qt-5.6.1 /usr/local/ qt-5.6.1 /usr/local/ qt-5.6.1 /usr/local/ qt-5.6.1

$ ./configure -qt-xcb -skip qtdeclarative
$ gmake
$ gmake install
Copy the code

(2) Configure the environment and edit the system environment variables; Enter vi /etc/profile in the terminal command line of the Longson server to open the corresponding file. Add the following code at the end of the file:

Export QTDIR= /usr/local/qt-5.6.1 export PATH=$QTDIR/bin:$PATH export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATHCopy the code

(3) Save the configuration and exit. Then run the source /etc/profile command to make the configuration take effect. (4) Verify that the installation is successful. Enter the qmake-version command on the terminal of the Loongson server. If the following information is displayed, the environment and configuration are successfully installed:

QMake version 3.0 Using Qt version 5.6.1 in /usr/local/qt-5.6.1 /libCopy the code

The Web implementation

TCP network communication flow

Loongson server terminal server and client running

Use the cross-compile toolchain GCC to generate a runnable file with instructions as followsgcc xxx.c -o xxx



To achieve server-side and client-side text data interaction

The server establishes communication

(1) In the process of data communication, two sockets are needed, one is monitoring socket, the other is communication socket

QTcpServer *tcpServer; QTcpSocket *tcpSocket; // Communication socketCopy the code

(2) The two socket variables defined in server.h need to be initialized in server.cpp, assign them to NULL, listen for socket space allocation, and specify the parent object

tcpServer=NULL;
tcpSocket=NULL;
tcpServer=new QTcpServer(this);
Copy the code

(3) when there is a client connection on the allocation of space, use connect function to connect, establish a socket for communication, take out the socket established a good connection to obtain the IP address and port number of the other side, in the window to display the successful connection;

The connect (tcpServer, & QTcpServer: : newConnection, [=] () {/ / remove and establish a good connection socket tcpSocket = tcpServer - > nextPendingConnection (); QString ip=tcpSocket->peerAddress().toString(); Qint16 port=tcpSocket->peerPort(); QString temp=QString("[%1 %2]: connection succeeded ").arg(IP).arg(port); ui->textEditRead->setText(temp); })Copy the code

(4) Select the send button in the UI interface, right-click and choose Go to slot function, so that the content of the editor can be obtained through the button and the content of the editor can be cleared, so as to achieve the corresponding function; (5) Determine whether the socket is established successfully. If not, return and output the message “server is disconnected, please reconnect”, or send the content in textEditWrite. DisconnectFrom Host and close functions of tcpsocket are used to disconnect.

if(NULL == tcpSocket) { return; } tcpSocket->write(" server down, please reconnect "); TcpSocket ->disconnectFromHost(); tcpSocket->close();Copy the code

Customer service establishes communication

(1) If a communication socket is needed in the client, define the communication socket in client.h first;

QTcpSocket *tcpSocket; // Communication socketCopy the code

(2) The communication socket variable defined in client.h needs to be initialized in client. CPP and assigned to NULL, and the communication socket allocates space and specifies the parent object;

tcpSocket = NULL; TcpSocket = new QTcpSocket(this);Copy the code

(3) When there is a connection between the server and the client, use the connect function to connect, establish a communication socket for communication, and print the “successful establishment of a good connection with the server” information, get the data sent by the other side, and add to the editor;

Connect (tcpSocket, &qtcpSocket ::connected, [=]() {UI ->textEditRead->setText(" connect to server successfully "); });Copy the code

(4) By defining IP and port variables and using lineEdit component to obtain IP number and port number, connectToHost function is used to actively establish a connection with the server;

QString IP = UI ->lineEditIP->text(); qint16 port = ui->lineEditPort->text().toInt(); TcpSocket ->connectToHost(QHostAddress(IP), port)Copy the code

(5) Select the send button on the UI interface, right-click the go to slot function, and obtain the contents of the edit box. Write data, read data and send data. Encode data as UTF-8 in this process to prevent garble, and finally clear the contents of the edit box;

QString STR = UI ->textEditWrite->toPlainText(); TcpSocket ->write(str.toutf8 ().data()); // Clear edit area contents UI ->textEditWrite->clear();Copy the code

(6) After data transmission, disconnectFrom Host and close functions of tcpsocket are used to disconnect the connection.

TcpSocket ->write(" Client is disconnected "); tcpSocket->disconnectFromHost(); tcpSocket->close();Copy the code

Resource portal

  1. Pay attention to [be a gentle program ape] public account
  2. In [do a tender program ape] public account background reply [Python information] [2020 autumn recruit] can get the corresponding surprise oh!

“❤️ thank you.”

  1. Click “like” to support it, so that more people can see this content.
  2. Share your thoughts with me in the comments section, and record your thought process in the comments section.
  • Excel/Word/CSV with Python
  • Programmers generally like to browse 40 websites, tun so many years, I will not hide private, personally strongly recommend
  • Image encryption and restoration based on chaotic Logistic encryption algorithm
  • Write two dozen lines of code to draw dynamic fireworks in Python
  • AttributeError: ‘Module’ object has no attribute ‘XXXXX’
  • How to parse XML and PDF easily in Python
  • Affine transformations (translation, rotation, scaling, and flipping) in Python
  • ValueError: Not enough values to unpack (Expected 3, got 2)
  • Python implements the raspberry PI camera to continuously record video and send it to the host
  • Image affine transform in Python – Extracting handwritten digital image samples
  • How to play with sound files in Python, cutting sounds into fragments according to the gaps
  • Python implementation of image mask mask processing, super detailed explanation!!

It’s not easy, kneel down… The following content includes the file interaction between the client and server and the complete code…

Thank you for your continued attention!!