1、char型数组或字符串指针转换成QString char str_data[512]; QString qs_data; ... qs_data = QString::fromLocal8Bit(str_data,512); //当然也可以用强制类型转换QString(str_data) 2、QString类型转换为 char指针类型 const char * str_data; //这里一定要加上const,否则会报错! QString qs_dat...
char* c_char = "world"; QString qstr = QString(QLatin1String(c_char)); 3. int ,float ,double to QString ①正规 int num = 79; float fnum = 79.99; QString qnum = QString::number(num); //默认为十进制转换,其他进制转换需显示指定 QString qnum = QString::number(fnum); QStrin...
5QString str1 = slist.join("/");<span></span> QString str1 = slist.join("/"); 6cout << str1; 将QStringList成员中所有QString单无用"/"合并成一个QString。 10. 字符串与QString转换 (1)字符串转QString,这个过程通常是自动转换的。 1QString str1("hello"); 2QString str2 ="Hi"...
1、QString转化为QByteArray类型,然后由QByteArray再转化为char*例: QString dome0; char dome1[20]; QByteArray dome2 = dome0.toLocal8Bit(); strcpy(dome1, dome2.data()); 2、QString转化为string类型,然后由string转化char* 例 QString dome0; char dome1[20]; std::string dome2 = dome0.to...
1. const char *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 转 string :QString text; string val = text.toStdString; string 转 char *:string var; char * var1 = var.c_str; char * 转 QString:QString val = QString(char * var); string 转 QString:string var; QString val = QString...
QString str_QString;std::string str_string;char*_pChar;inta; 1、 str_QString=str_string.c_str();str_QString=QString(_pChar);str_QString=QString::number(a); 2、 str_string = str_QString.toStdString; str_string = str_QString.local8Bit(); ...
QByteArray byteArray;unsigned char * p = (unsigned char *)byteArray.data();
int main(int argc, char **argv) { QApplication app(argc, argv); QString str1 = "Test"; QByteArray ba = str1.toLatin1(); const char *c_str2 = ba.data(); return app.exec(); } To convert a char* to a QString you can use the QString constructor that takes a QLatin1String...