【Qt】随机字符串

文章目录

Qt生成自定义字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
qsrand(QDateTime::currentMSecsSinceEpoch());
const char ch[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int size = sizeof(ch);
char* str = new char[nLen + 1];
int num = 0;
for (int nIndex = 0; nIndex < nLen; ++nIndex)
{
num = rand() % (size - 1);
str[nIndex] = ch[num];
}
str[nLen] = '\0';

QString res(str);

QLOG_INFO() << __FUNCTION__ << __LINE__ << res;

m_RandomCode = res;