QT self-study course record (8-1): Qt part of the basic algorithm

1 Contents and resource Index

  QT self-learning course catalog and resource Index

2 References

  1, Qt Learning (II) algorithm (qAbs (), qMax (), qRound (), qSwap ()) and regular expressions

3 base commonly used algorithms

3.1 Qt5 commonly used algorithms

  To show a piece of code as follows:

#include <QDebug>

int main(int argc, char *argv[])
{
	double a = -19.3, b = 9.7;
	double c = qAbs(a);				// 取a的绝对值
	double max = qMax(b, c);		// 取b c中的最大值

	int bn = qRound(b);				// 取与b最接近的一个整数值,四舍五入
	int cn = qRound(c);

	qDebug() << "a = " << a;				// 输出打印 a
	qDebug() << "b = " << b;				// 输出打印 b
	qDebug() << "c = qAbs(a) = " << c;		// 输出打印 c
	qDebug() << "qMax(b, c) = " << max;		// 输出打印 max
	qDebug() << "bn = qRound(b) = " << bn;	// 输出打印 bn
	qDebug() << "cn = qRound(c) = " << cn;	// 输出打印 cn

	qSwap(bn, cn);							// 交换 bn cn
	qDebug() << "qSwap(bn, cn): " << "bn = " << bn << "cn = " << cn;	// 输出打印 bn cn

	return 0;
}

  FIG output results are as follows:
  Here Insert Picture Description

  For some arithmetic functions provided by the program, one by one split explain:

  • qAbs ()
    This function in C / C ++ is a required function in absolute value, but in Qt, add another layer of the package, but the essence is the same.

  • qMax ()
    function, it is clear that you, a look at the name that this is the maximum value of the comparison between the two numbers, then the function returns.

  • qRound ()
    This function is rounded, to pass in a parameter, in accordance with the principles of rounding, rounding, and then returns.

  • qSwap ()
    When this function is a swap function, pass in two parameters A, B, performing this operation, put the A, B to exchange the true value. Code implementation process similar to the following:

int a, b, c;

a = 10;
b = 20;

c = a;		// c = 10
a = b;		// a = 20
b = c;		// b = 10

c = 0;
  • Reference data interpretation functions as follows:
    Here Insert Picture Description

4 Summary

  1. In the QT software, the direct use F1 Help command, you can not find the corresponding path needs to be further explored.
  2. There are many algorithms function, here is to use a part of the follow-up may further be useful to find relevant information and so on.
  3. The need for further understanding of digestion, the conversion of record for their own.
Published 88 original articles · won praise 84 · views 120 000 +

Guess you like

Origin blog.csdn.net/Fighting_Boom/article/details/103817671