itop4412 development board Qt serial port programming-interface layout
[Copy link]
In this section, we use Qt to write a simple host computer.
Experimental introduction: Assemble the UI interface and use the serial port class provided by Qt to implement the serial port receiving and sending functions. The relevant Qt knowledge that needs to be mastered are as follows:
QSerialPort is an additional module in Qt5, which provides basic functions, including configuration, I/O operation, obtaining and setting the signal of RS-232 pins. To link the QtSerialPort module, you need to add +=serialport in the .pro file.
QSerialPort encapsulates a wealth of member variables to correspond to serial port properties, and there are many member functions for operating serial ports. Commonly used member functions include setPort() or setPortName(), setBaudRate(), setDataBits(), setStopBits(), setParity(), etc. These functions can be used to set the serial port device to be accessed. This experiment uses the readyRead() signal. When data arrives, the readyRead() signal of the class object will be triggered, and then its member function readAll() will be used to read.
The class QSerialPortInfo can obtain available serial port information, such as port name, system location, product number, description, manufacturer and other information. We pass the obtained port information to the QSerialPort class object.
77.1 Interface layout
Step 1: Drag the controls to the UI interface
Use Plain Text Edit for the receiving box, lineEdit for the sending box, and Combo Box for the property selection component.
Step 2: Layout of the property setting bar. Take the serial port number as an example and layout the property selection bits horizontally in sequence.
Then select all the property selection boxes and click vertical layout
The effect is as follows:
Step 3: Layout of the function bar. Add springs between the buttons and click horizontal layout.
Select Lbel, the send box and the function button, and click on the vertical layout
As shown:
Select the property bar and the components on the right, and then click on the horizontal layout, as shown:
After completion:
Follow the above method to vertically layout the function part and the receiving box below:
After adding the components, change the receiving box to read-only: Click on the receiving box and mark readOnly in QTextEdit.
Change the UI interface object name in the upper right corner. After the interface is assembled, you can modify it as needed.
Double-click the attribute selection box to add attributes:
As shown:
Search for more content on Bilibili
|