0
点赞
收藏
分享

微信扫一扫

Qt随机字符

思考的鸿毛 2022-03-15 阅读 29

随机字符需要用到系统时间

//随机字符
QString MainForm::randCharToStr()
{
    int max = 4;//字符串长度
    QString tmp = QString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    QString str ;
    QTime t;
    t = QTime::currentTime();
    qsrand(t.msec()+t.second()*1000);
    for(int i=0;i<max;i++)
    {
        int len = qrand()%tmp.length();
        str[i] =tmp.at(len);
    }
    QDateTime current_time = QDateTime::currentDateTime();
    QString currentDateStr = current_time.toString("hh:mm");
    currentDateStr.remove(2,1);
    info.setSysInfoSystemRandStr(currentDateStr + str);
    return currentDateStr + str;
}

举报

相关推荐

0 条评论