本文整理汇总了C++中QTextCodec类的典型用法代码示例。如果您正苦于以下问题:C++ QTextCodec类的具体用法?C++ QTextCodec怎么用?C++ QTextCodec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextCodec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckError
bool Pack::CheckError(QProcess &pprocess)
{
QTextCodec *gbk = QTextCodec::codecForName("GBK");
QString error = gbk->toUnicode(pprocess.readAllStandardError());
if (error.toLower().contains("error:")
|| error.toLower().contains("exception:")
|| error.toLower().contains(" error")
|| error.toLower().contains(" exception")
|| error.toLower().contains("build failed")){
QString standardOut = gbk->toUnicode(pprocess.readAllStandardOutput());
emit GenerateError(error.append(standardOut));
return false;
}
return true;
}
示例2: updateBuddyListView
void EvaQunMemberPicker::updateBuddyListView()
{
//if(!mQun) return;
lvBuddyList->clear();
QTextCodec *codec = QTextCodec::codecForName("GB18030");
std::list<std::string> names = EvaMain::user->getGroupNames();
std::list<std::string>::iterator groupIter;
int i=0;
for(groupIter = names.begin(); groupIter!= names.end(); ++groupIter){
QString g = codec->toUnicode(groupIter->c_str());
QCheckListItem *item = new QCheckListItem(lvBuddyList, g, QCheckListItem::CheckBox);
item->setState(QCheckListItem::Off);
groups[i++] = item;
}
//QunInfo info = mQun->getDetails();
std::map<unsigned int, QQFriend>::iterator iter;
std::map<unsigned int, QQFriend> list = (EvaMain::user->getFriendList()).getAllFriendsMap();
for(iter = list.begin(); iter != list.end(); ++iter){
int id = iter->second.getQQ();
QString nick = EvaTextFilter::filter(codec->toUnicode(iter->second.getNick().c_str()));
int groupIndex = iter->second.getGroupIndex();
QCheckListItem *group = groups[groupIndex];
if(!group) continue;
short faceID = (iter->second.getFace())/3 + 1;
if(faceID<1) faceID = 1;
QCheckListItem *item = new QCheckListItem(group, nick + "(" + QString::number(id) + ")", QCheckListItem::CheckBox);
QPixmap *pic = EvaMain::images->getFace(faceID, true);
if(pic) {
QImage img(pic->convertToImage().smoothScale(16, 16));
item->setPixmap(0, QPixmap(img));
}else{
fprintf(stderr, "EvaQunMemberPicker::updateBuddyListView (id:%d, faceID:%d, %s) -- NULL QPixmap pointer, ignored!\n", id, faceID, nick.ascii());
}
if(mQun && mQun->hasMember(id))
item->setState(QCheckListItem::On);
else
item->setState(QCheckListItem::Off);
buddyList[id] = item;
}
}
示例3: find_winamp
bool KviWinampInterface::playMrl(const QString & mrl)
{
HWND hWinamp = find_winamp(this);
if(hWinamp)
{
QTextCodec * c = mediaplayer_get_codec();
KviCString szMrl = c ? c->fromUnicode(mrl) : mrl.toUtf8();
COPYDATASTRUCT cds;
cds.dwData = IPC_PLAYFILE;
cds.lpData = (void *)szMrl.ptr();
cds.cbData = szMrl.len() + 1; // include space for null char
SendMessage(hWinamp, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
return true;
}
return false;
}
示例4: on_openlib_clicked
void ExcLoadDlg::on_openlib_clicked()
{
if( m_libpath.isEmpty() ) {
m_libpath = m_curpath;
}
QTextCodec *codec = QTextCodec::codecForLocale();
QString name = QFileDialog::getExistingDirectory(
this, codec->toUnicode("打开异常对应的elf文件和库路径"), m_libpath );
if(!name.isEmpty()) {
m_curpath = name;
m_libpath = name;
m_ui.LibPath->setText(name);
}
}
示例5: uchardet_new
QString TagSetData::decode(const Tag &tag) const
{
if (tag.encoded)
return QTextCodec::codecForName(ENC_CODEC)->toUnicode(tag.value);
if (!mTextCodec)
{
// Auto detect codepage ...........................
uchardet_t uc = uchardet_new();
for(int i=0; i<mTrackCount; ++i)
{
const QByteArray &performer = mTags.value(key(i, TAG_PERFORMER)).value;
const QByteArray &title = mTags.value(key(i, TAG_TITLE)).value;
uchardet_handle_data(uc, performer.data(), performer.length());
uchardet_handle_data(uc, title.data(), title.length());
}
uchardet_data_end(uc);
mTextCodec = QTextCodec::codecForName(uchardet_get_charset(uc));
if (!mTextCodec)
mTextCodec = QTextCodec::codecForName("UTF-8");
uchardet_delete(uc);
}
return mTextCodec->toUnicode(tag.value);
}
示例6: readWithEncoding
bool Serializer::readWithEncoding(const QString& filename, const QString& encoding,
QString &txt)
{
QByteArray file;
QTextCodec *codec;
if (encoding.isEmpty())
codec = QTextCodec::codecForLocale();
else
codec = QTextCodec::codecForName(encoding.toLocal8Bit());
if (loadRawText(filename, file))
{
txt = codec->toUnicode( file.data() );
return true;
}
return false;
}
示例7: doc
doctorChangeDialog::doctorChangeDialog( QWidget *parent, doctor* doc )
: doc(doc), QDialog(parent)
{
ui.setupUi(this);
QByteArray fio(doc->fio), dolgnost(doc->dolgnost), work(doc->priem);
//QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
QTextCodec *codec = QTextCodec::codecForName("CP866");
QString fioString = codec->toUnicode(fio);
QString dolgnostString = codec->toUnicode(dolgnost);
QString workString = codec->toUnicode(work);
ui.fio->setText( fioString );
ui.cabinet->setText( QString::number( doc->cabinet ) );
ui.speciality->setText( dolgnostString );
ui.workHours->setText( workString );
}
示例8: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
if (argc > 1) {
QTextCodec* textCodec = QTextCodec::codecForLocale();
if (textCodec) {
w.openFile(textCodec->toUnicode(argv[1]));
}
}
w.show();
return a.exec();
}
示例9: file
void ReportView::load()
{
QFile file(reportFileName);
if(!file.open(QFile::ReadOnly | QFile::Text))
qDebug() << "not file open " << file.errorString() << endl;
else
{
QByteArray data = file.readAll();
QTextCodec *codec = Qt::codecForHtml(data);
QString str = codec->toUnicode(data);
if (Qt::mightBeRichText(str))
{
ui->textEdit->setHtml(str);
}
}
}
示例10: actionCharacterEncoding
void MainWindow::actionCharacterEncoding(QAction *action)
{
QString encoding;
if (action && action->data().toInt() > 0)
{
QTextCodec *codec = QTextCodec::codecForMib(action->data().toInt());
if (codec)
{
encoding = codec->name();
}
}
m_windowsManager->setDefaultCharacterEncoding(encoding.toLower());
}
示例11: getAmipString
QString getAmipString(const char * var)
{
QString szRet;
QString szString = eval_str(var);
QTextCodec * pCodec = mediaplayer_get_codec();
if(pCodec) {
#if (QT_VERSION < 0x050000)
szRet = pCodec->toUnicode(szString.toLatin1());
#else
szRet = pCodec->toUnicode(szString.toUtf8());
#endif
} else {
szRet = szString;
}
return szRet;
}
示例12: out
//************************************************************************************************
void tGuiError::ExeCommand(QDataStream& _in)
{
int num_error=-9999;
QString error="";
QString detail="";
QString client_detail="";
_in >> num_error;
_in >> error;
_in >> detail;
_in >> client_detail;
//Отмена транзакции из-за ошибки
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
block.clear();
QString command="CancelTransaction";
out << command;
emit SendCommand(block);
/*
QTextCodec *codec =QTextCodec::codecForName("Windows-1251");
// QTextCodec *codec =QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForTr(codec);
QTextCodec::setCodecForCStrings(codec);
QString before="\\";
QString after="/";
QString ret=codec->toUnicode(_path.replace(before, after).toAscii());
*/
QTextCodec *codec =QTextCodec::codecForName("Windows-1251");
QTextCodec::setCodecForTr(codec);
QTextCodec::setCodecForCStrings(codec);
QMessageBox MB;
QString S=QString::fromUtf8("Ошибка в команде ")+QString::number(num_error)+"\n"+client_detail;
QString S1=codec->toUnicode(S.toAscii())+"\n"+detail;
MB.setText(S1);
MB.setWindowTitle(error);
MB.exec();
}
示例13: property
bool pEditor::saveFile( const QString& s )
{
if ( !isModified() )
return true;
// get filename
QString fn = s;
if ( s.isEmpty() )
fn = property( "fileName" ).toString();
// get path
QString fp = QFileInfo( fn ).path();
// filename
QFile f( fn );
// filename dir
QDir d;
// create bak folder
if ( !d.exists( fp ) )
if ( !d.mkpath( fp ) )
return false;
// set correct path
d.setPath( fp );
// try open file to write in
if ( !f.open( QFile::WriteOnly ) )
{
MonkeyCore::messageManager()->appendMessage( tr( "Cannot write file %1:\n%2." ).arg( fn ).arg( f.errorString() ) );
return false;
}
// writing file
QApplication::setOverrideCursor( Qt::WaitCursor );
f.resize( 0 );
QTextCodec* c = QTextCodec::codecForName( property( "codec" ).toString().toUtf8() );
bool ok = f.write( c->fromUnicode( text() ) ) != -1;
if ( ok )
{
setModified( false );
setProperty( "fileName", fn );
}
QApplication::restoreOverrideCursor();
return ok;
}
示例14: qt_encoding_id_for_mib
/*!
Internal function that initializes the font system.
\internal
The font cache and font dict do not alloc the keys. The key is a QString
which is shared between QFontPrivate and QXFontName.
*/
void QFont::initialize()
{
extern int qt_encoding_id_for_mib(int mib); // from qfontdatabase_x11.cpp
QTextCodec *codec = QTextCodec::codecForLocale();
// determine the default encoding id using the locale, otherwise
// fallback to latin1 (mib == 4)
int mib = codec ? codec->mibEnum() : 4;
// for asian locales, use the mib for the font codec instead of the locale codec
switch (mib) {
case 38: // eucKR
mib = 36;
break;
case 2025: // GB2312
mib = 57;
break;
case 113: // GBK
mib = -113;
break;
case 114: // GB18030
mib = -114;
break;
case 2026: // Big5
mib = -2026;
break;
case 2101: // Big5-HKSCS
mib = -2101;
break;
case 16: // JIS7
mib = 15;
break;
case 17: // SJIS
case 18: // eucJP
mib = 63;
break;
}
// get the default encoding id for the locale encoding...
QFontPrivate::defaultEncodingID = qt_encoding_id_for_mib(mib);
}
示例15: QActionGroup
void MainWindow::menuCharacterEncodingAboutToShow()
{
if (!m_characterEncodingGroup)
{
QList<int> textCodecs;
textCodecs << 106 << 1015 << 1017 << 4 << 5 << 6 << 7 << 8 << 82 << 10 << 85 << 12 << 13 << 109 << 110 << 112 << 2250 << 2251 << 2252 << 2253 << 2254 << 2255 << 2256 << 2257 << 2258 << 18 << 39 << 17 << 38 << 2026;
m_characterEncodingGroup = new QActionGroup(this);
m_characterEncodingGroup->setExclusive(true);
QAction *defaultAction = m_ui->menuCharacterEncoding->addAction(tr("Auto Detect"));
defaultAction->setData(-1);
defaultAction->setCheckable(true);
m_characterEncodingGroup->addAction(defaultAction);
m_ui->menuCharacterEncoding->addSeparator();
for (int i = 0; i < textCodecs.count(); ++i)
{
QTextCodec *codec = QTextCodec::codecForMib(textCodecs.at(i));
if (!codec)
{
continue;
}
QAction *textCodecAction = m_ui->menuCharacterEncoding->addAction(Utils::elideText(codec->name(), m_ui->menuCharacterEncoding));
textCodecAction->setData(textCodecs.at(i));
textCodecAction->setCheckable(true);
m_characterEncodingGroup->addAction(textCodecAction);
}
}
const QString encoding = m_windowsManager->getDefaultCharacterEncoding().toLower();
for (int i = 2; i < m_ui->menuCharacterEncoding->actions().count(); ++i)
{
QAction *action = m_ui->menuCharacterEncoding->actions().at(i);
if (!action)
{
continue;
}
action->setChecked(encoding == action->text().toLower());
if (action->isChecked())
{
break;
}
}
if (!m_characterEncodingGroup->checkedAction())
{
m_ui->menuCharacterEncoding->actions().first()->setChecked(true);
}
}