lineEdit_2->text(); // cname = ui->lineEdit_2->text().toLatin1().da_“qstring str = ui->lineedit_2->text();”的作用是________。">
赞
踩
Qstring chage char*
fp = fopen("C:\\Users\\Public\\system.ini","w"); /*文本方式写入*/
const char* cname;
QString str= ui->lineEdit_2->text();
// cname = ui->lineEdit_2->text().toLatin1().data();
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
// QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
cname = str.toLocal8Bit().data();//字符串转化
// cname = QUOTE::fromUtf8(str.toLocal8Bit().data()).toLatin1().data();
//cname=ui->lineEdit_2->text().toLocal8Bit();
// CString str( name.c_str() );
// cname = (LPSTR)(LPCTSTR)st;
// strcpy (cname, name.c_str());//string 转c字符串
// fprintf(stream,"%s%ld%f%c","hello world",
// 65000,3.14159,'x');
// printf("%s",cname
// );
fprintf(fp,"%s",cname
);
fclose(fp);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化
// fp1 = fopen("C:\\Users\\Public\\widows.ini","r"); /*文本方式写入*/
情形2:Qsting chage char* 最好用 前提是main函数用的是GBK库
char* ch;// QByteArray ba = contact.toLatin1();
// QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));ch = contact.toLocal8Bit().data();//字符串转化trayIcon->showMessage(tr(ch),tr(""),QSystemTrayIcon::Information,2000);QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); //保证写出的文字显示不乱码 编码格式的转化 因为main函数中默认用 GBK转汉字所以此时应该改回为GBK举例2:
QString qstr=ui->textEdit->toPlainText();char* ch;// QByteArray ba = contact.toLatin1();// QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));// QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));ch = qstr.toLocal8Bit().data();//字符串转化FILE * fp1=fopen("./name.dat","a");fprintf(fp1,"%s\n",ch);fclose(fp1); //这儿获取的数字最准确 获取时间列表的时间 自己加 应该写在保存之后的内容里QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));//QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化char* chage Qstring情形1:fp = fopen("C:\\Users\\Public\\system.ini","r"); /*文本方式写入 以前也是r */// fp = fopen("C:\\Users\\Public\\system.ini","a+"); /*文本方式写入 以前也是r */
fp1 = fopen("C:\\Users\\Public\\widows.ini","r"); /*文本方式写入*/char name[50]={}; //有初始化的必要 不然开始会乱码fscanf(fp, "%s",name);// ui->lineEdit_2->setText( QString(QLatin1String(name))); //char 转// ui->lineEdit_2->setText( QString(name)); //char 转//旁边的名字栏显示的汉字QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); //保证写出的文字显示不乱码 编码格式的转化//用GBK编的码就用gbk来解码白框里显示名字ui->lineEdit_2->setText( QString(tr(name))); //char 转//QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
//QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
//cname = str.toLocal8Bit().data();
// QTextCodec *textcod = QTextCodec::codecForName("GBK");
// QString string1 = textcod ->fromUnicode(listbox1->currentText());
// strcpy(name,string1);
// ui->lineEdit_2->setText( string1);
fscanf(fp1,"%d",&mit);// ui->lineEdit_3->text().QString::number(mit); //得到
ui->lineEdit_3->setText(QString::number(mit) );fclose(fp);fclose(fp1);QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //弹出的对话框中显示的文字
情形2:QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化//用GBK编的码就用gbk来解码白框里显示名字QString t2= QString(tr(itime1[i])); //char 转itime1[i] 为char类型QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); //弹出的对话框中显示的文字注意:trayIcon->showMessage(tr("我爱你"),tr(""),QSystemTrayIcon::Information,2000); //所以 tr里面的是char* 字符串http://www.cnblogs.com/Romi/archive/2012/03/12/2392478.htmlhttp://www.cnblogs.com/findumars/p/4851236.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。