foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())是什么意思
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())是Qt框架中的一个语法结构,用于遍历系统中所有可用的串口。其中QSerialPortInfo::availablePorts()返回系统中所有可用串口的列表,而foreach则是用于遍历这个列表,并对其中每个串口信息进行处理。
这个语法结构中,const QSerialPortInfo &info是迭代变量,表示QSerialPortInfo::availablePorts()返回的列表中的每个元素。在每次迭代中,都会将列表中的一个串口信息赋值给info,并执行紧随其后的代码块。在这个代码块中,可以使用info来访问当前迭代到的串口信息。
如果你需要使用串口进行通信,这个语法结构可以帮助你获取系统中所有可用的串口,并为每个串口信息执行相应的操作。
void QSerialPort::setPort(const QSerialPortInfo & serialPortInfo)
Sets the port stored in the serial port info instance serialPortInfo.
这端口被设置,存储在在serialPortInfo对象中的串口信息
bool QSerialPort::open(OpenMode mode)
Reimplemented from QIODevice::open().
Opens the serial port using OpenMode mode, and then returns true if successful; otherwise returns false and sets an error code which can be obtained by calling the error() method.
使用xx模式打开串口,成功返回true;否则返回false ,当调用 error()函数时候会返回设置的错误代码
Note: The method returns false if opening the port is successful, but could not set any of the port settings successfully. In that case, the port is closed automatically not to leave the port around with incorrect settings.
注意:这方法返回false ,尽管打开成功,但是不会设置这端口设置(就是打开了,也不会是按照xx模式打开);在这情况下,这端口自动关闭,不会离开端口的错误设置环境;
Warning: The mode has to be QIODevice::ReadOnly, QIODevice::WriteOnly, or QIODevice::ReadWrite. Other modes are unsupported.
bool QSerialPort::clear(Directions directions = AllDirections)
Discards all characters from the output or input buffer, depending on given directions directions. This includes clearing the internal class buffers and the UART (driver) buffers. Also terminate pending read or write operations. If successful, returns true; otherwise returns false.
忽略输出输入的字符串,取决于 “directions ” 方向;包含清除内部类缓存,和串口缓存。也结束等待读写项。如果关闭成功,返回true,否则false
QString QString::trimmed() const
Returns a string that has whitespace removed from the start and the end.
去头去尾,只指定特定的字符,例如空格和换行;
Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.
Example:
QString str = " lots\t of\nwhitespace\r\n ";
str = str.trimmed();
// str == "lots\t of\nwhitespace"
int QString::toInt(bool * ok = 0, int base = 10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
转化字符串转换成base的进制,默认为10,必须是10到36,or 0.转换失败返回0;
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
如果当前转换错误,ok是false;否则是true;
If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
如果base为0,自动识别c语言的符号进制数;
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toInt()