Qstring str="FF";bool ok;int dec=str.toInt(&ok,10);//dec=255 ; ok=rueint hex =str.toInt(&ok,16);//hex=255;ok=true;
3.常整形转换为Qstring形
long a =63;QString str=QString::number(a,16);//str="3f";QString str=QString::number(a,16).toUpper();//str="3F";
Qstring 转换char*问题!
方法一:
QString qstr("hello,word");constchar * p = qstr.toLocal8Bit().data();
方法二:
constchar *p = qstr.toStdString().data();
转换过来的是常量
把当前时间转化为QString...
public QDateTime qdate = QDateTime.currentDateTime();
datetime = qdate.toString("yyyy年MM月dd日ddddhh:mm:ss");
如果不是QTime和QDate类比如说:通过TCP/IP接收到的char unsigned char 类等如何转换为QString类
QString Time2String( DWORD dwTime)
{
char cTime[50] = {0};
memset(cTime,0,50);
strftime(cTime,32,"%Y-%m-%d %H:%M:%S",localtime(&time_t(dwTime)));
return QString(cTime);
}
由于我采用Qt来写的界面,所以用到了QString类型
1. QString和string的相互转换
// QString and string changeQString s2q(const string &s){return QString(QString::fromLocal8Bit(s.c_str()));}string q2s(const QString &s){return string((constchar *)s.toLocal8Bit());}
2. QString to Char*
QString data;data.toLatin1().data();
3. char to number
int char2num(char ch){if(ch>='0'&&ch