最近做了一个qt的应用,总结下:
1.base64编码和解码
编码:
QString tmp_in=“xxxxxxxxx”;
QString base64=QString(tmp_in.toBase64());
解码:
QByteArray tmp_out (base64.toUtf8());
QString dataid=QString( QByteArray::fromBase64(tmp_out));
2.找到控件,比如textedit
ui_edittext1 = findChild<QTextEdit*>("textEdit");
3.绑定响应
connect(installbutton,SIGNAL(clicked()),this,SLOT(generatedata()));
generatedata()为响应函数;
4.获取edittext内容
QString IDdata=ui_edittext1->toPlainText();
5.byte数组与qstring转换
QByteArray tmp_in (data.toUtf8());
QString base64=QString(tmp_in.toBase64());
6.获取字符串的hashcode
int hashCode = 0;
for (int i = 0; i < IDdata.count(); ++i)
hashCode = hashCode * 31 + IDdata.at(i).unicode();
7.数字与字符串互转
QString s = QString::number(hashCode, 10);
int inthashcode=tem.toInt();
8.获取某个字符在字符串的索引
int len = out.indexOf(':');
9.获取特定字符的左边字符串
QString data2=out.left(len);
10.删掉一段字符串
QString tem=out.remove(0,len+1);