Assign a value to the char[] array with qstring

Source: Internet
Author: User

Tree_data. Desc//desc is a char[80] type of data

Qstring Newdescstr;

strcpy (Tree_data. Desc,

Newdescstr.tolocal8bit (). data ());

Attention:

. Tolocal8bit () in order to make qstring into Qbytearray, but also for the localization of Chinese characters;. Data () is converting Qbytearray to char*

Sometimes when you print SQL statements,. Tolocal8bit () and. Data () cannot be written in succession, and must be carried out in two steps;

Also write a function, if you often need to do so, you can call the function

Populate the content of STR with the buff
int Dbcfgfun::inputstrtobuff (char *buff, QString Str, int bufflen)
{
if (!buff | | bufflen<=0 | | Str.length () <=0)
{
return-1;
}


memset (Buff, 0, Bufflen);
int Reallen = (str.tolocal8bit (). Length () <bufflen? Str.tolocal8bit (). Length (): Bufflen);
if (reallen>0)
{
memcpy (Buff, Str.tolocal8bit (). Data (), Reallen);
}
Buff[bufflen-1] = 0;
return Reallen;
}

Assign a value (go) to the char[] array with qstring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.