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 all kinds of character conversion in Qt

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to achieve all kinds of character conversion in Qt". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to achieve all kinds of character conversion in Qt" can help you solve the problem.

Conversion from Qt int to QStringint I = 5 HELLOstr QString s = QString::number (I); Qt Foundation-QString case conversion QString str = "hello"; str = str.toUpper (); / / conversion to uppercase HELLOstr = str.toLower (); / / conversion to lowercase helloQByteArray to char* 2.1 QByteArray to char* mode 1 traditional mode data () and size () function (convenience) QByteArray array (10,'Q') / / initialize / / convert char * buf;// is just the length of a pointer int len;//buf buf = array.data (); len = array.size (); way 2 memcpy () way (flexible) QByteArray array (9LQ Q'); char buf [10]; / / Array int len_array = array.size (); int len_buf = sizeof (buf); int len = qMin (len_array, len_buf) / / convert memcpy (buf, array, len); convert 2.QByteArray to int and int [] 2.1. Conversion between int and QByteArray [1] int to QByteArray// int to QByteArrayint intVar = 1999; QByteArray array;int len_intVar = sizeof (intVar); array.resize (len_intVar); memcpy (array.data (), & intVar, len_intVar); [2] QByteArray to int// QByteArray to int// array data connection int outIntVar;memcpy (& outIntVar, array.data (), len_intVar); / memcpy (& outIntVar, array, len_intVar); / / this line code is common to the previous sentence. Interchange between int [] and QByteArray [1] int [] to QByteArray// int [4] to QByteArrayint intVar [4] = {1pje 2je 9pm 0}; / / initialization variable assignment QByteArray array;int len_intVar = sizeof (intVar); array.resize (len_intVar); / / convert int []-> QByteArraymemcpy (array.data (), & intVar, len_intVar); [2] QByteArray to int [] / QByteArray to int [] / array data connection to int outIntVar [4] Memcpy (& outIntVar, array.data (), len_intVar); / / memcpy (& outIntVar, array, len_intVar); / / the conversion between this line of code and the previous sentence general 3.QByteArray and float and float [] can actually refer to Section 3, the usage of int. 3.1. Float [] to QByteArray [1] float [] to QByteArray// float [4] to QByteArrayfloat fVar [4] = {1.1,2.3,9.5,0.2}; / / initialization variable assignment QByteArray array;int len_fVar = sizeof (fVar); / / 4x4 = 16 (a float occupies 4 bytes) array.resize (len_intVar); memcpy (array.data (), & fVar, len_fVar) [2] QByteArray to float [] / / QByteArray to float [] float outFvar [4]; memcpy (& outIntVar, array.data (), len_fVar); / / memcpy (& outFvar, array, len_fVar); / / this line of code is common to the previous sentence. The conversion between float and QByteArray can safely refer to int. This is the end of the introduction of "how to achieve various character conversions in Qt". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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: 0

*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

Development

Wechat

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

12
Report