当前位置: 首页>>代码示例>>C++>>正文


C++ QTextCodec::fromUnicode方法代码示例

本文整理汇总了C++中QTextCodec::fromUnicode方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCodec::fromUnicode方法的具体用法?C++ QTextCodec::fromUnicode怎么用?C++ QTextCodec::fromUnicode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextCodec的用法示例。


在下文中一共展示了QTextCodec::fromUnicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ExecuteCmd

bool Pack::ExecuteCmd(QString exe, QStringList argument, QProcess &pprocess, QString workPath)
{
	QString enterPath = QStringLiteral("cd ") + "\"" + workPath + "\"" + QStringLiteral("\n");
	QString arg;
	arg.append(exe);
	for (QStringList::Iterator ite = argument.begin(); ite != argument.end(); ite++)
	{
		arg.append(" ");
		arg.append(*ite);		
	}
	arg.append("\n");
	pprocess.start("cmd");
	pprocess.waitForStarted();
	QTextCodec *gbk = QTextCodec::codecForName("GBK");
	QByteArray byteEnterPath = gbk->fromUnicode(enterPath.constData(), enterPath.length());
	QByteArray byteCommand = gbk->fromUnicode(arg.constData(), arg.length());
	char *charEnterPath = byteEnterPath.data();
	char *charCommand = byteCommand.data();
	pprocess.write(byteEnterPath);
	pprocess.write(charCommand);
	pprocess.closeWriteChannel();
	if (!pprocess.waitForFinished(1000 * 60 * 20)){
		return false;
	}
	return true;
	//mpprocess->setWorkingDirectory(workPath);
	//mpprocess->start(exe,argument);
}
开发者ID:langelee,项目名称:AutopackingAndroid,代码行数:28,代码来源:Pack.cpp

示例2: fromUnicode

QByteArray fromUnicode(const QString &data)
{
#ifdef Q_OS_WIN
    return data.toUtf8();
#else
    QTextCodec *locale = QTextCodec::codecForLocale();
    QByteArray result;
    char buffer[30000];
    uint buffer_len = 0;
    uint len = 0;
    int offset = 0;
    const int part_len = 5000;

    QString part;

    while (offset < data.length()) {
        part = data.mid(offset, part_len);
        QByteArray test = locale->fromUnicode(part);
        if (locale->toUnicode(test) == part) {
            result += test;
            offset += part_len;
            continue;
        }
        len = part.length();
        buffer_len = 0;
        for (uint i = 0; i < len; i++) {
            QByteArray test = locale->fromUnicode(part.mid(i, 1));
            if (locale->toUnicode(test) == part.mid(i, 1)) {
                if (buffer_len + test.length() + 1 > sizeof(buffer)) {
                    break;
                }
                strcpy(buffer + buffer_len, test.data());
                buffer_len += test.length();
            } else {
                QString res;
                res.sprintf("&#%d;", part.at(i).unicode());
                test = locale->fromUnicode(res);
                if (buffer_len + test.length() + 1 > sizeof(buffer)) {
                    break;
                }
                strcpy(buffer + buffer_len, test.data());
                buffer_len += test.length();
            }
        }
        result += QByteArray(buffer, buffer_len + 1);
        offset += part_len;
    }
    return result;
#endif
}
开发者ID:KDE,项目名称:kdoctools,代码行数:50,代码来源:xslt.cpp

示例3: hexCode

QString FontDocument::hexCode(const QString &key, const QString &encoding, bool bom) const
{
  QString result;
  QTextCodec *codec = QTextCodec::codecForName(encoding.toLatin1());

  QChar ch = key.at(0);
  QByteArray codeArray = codec->fromUnicode(&ch, 1);

  quint64 code = 0;

  for (int i = 0; i < codeArray.count() && i < 8; i++) {
    code = code << 8;
    code |= (quint8)codeArray.at(i);
  }

  if (encoding.contains("UTF-16")) {
    // reorder bytes
    quint64 a =
      ((code & 0x000000000000ff00ULL) >> 8) |
      ((code & 0x00000000000000ffULL) << 8);
    code &= 0xffffffffffff0000ULL;
    code |= a;

    if (bom) {
      // 0xfeff00c1
      result = QString("%1").arg(code, 8, 16, QChar('0'));
    } else {
      // 0x00c1
      code &= 0x000000000000ffffULL;
      result = QString("%1").arg(code, 4, 16, QChar('0'));
    }
  } else if (encoding.contains("UTF-32")) {
开发者ID:riuson,项目名称:lcd-image-converter,代码行数:32,代码来源:fontdocument.cpp

示例4: uploadTracks

void CDeviceGarmin::uploadTracks(const QList<CTrack*>& trks)
{
    qDebug() << "CDeviceGarmin::uploadTracks()";

    Garmin::IDevice * dev = getDevice();
    if(dev == 0) return;

    std::list<Garmin::Track_t> gartrks;
    QTextCodec *codec = QTextCodec::codecForName(CResources::self().charset().toLatin1());

    QList<CTrack*>::const_iterator trk = trks.begin();
    while(trk != trks.end())
    {
        Garmin::Track_t gartrk;

        gartrk.ident = codec->fromUnicode((*trk)->getName()).data();
        gartrk.color = (*trk)->getColorIdx();

        const QList<CTrack::pt_t>& trkpts           = (*trk)->getTrackPoints();
        QList<CTrack::pt_t>::const_iterator trkpt   =  trkpts.begin();
        while(trkpt != trkpts.end())
        {
            Garmin::TrkPt_t gartrkpt;

            QDateTime t = QDateTime::fromTime_t(trkpt->timestamp);
            t = t.addYears(-20).addDays(1);

            gartrkpt.time   = t.toTime_t();
            gartrkpt.lon    = trkpt->lon;
            gartrkpt.lat    = trkpt->lat;
            gartrkpt.alt    = trkpt->ele;

            gartrk.track.push_back(gartrkpt);
            ++trkpt;
        }

        gartrks.push_back(gartrk);
        ++trk;
    }

    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    try
    {
        dev->uploadTracks(gartrks);
        if (CResources::self().playSound())
        {
            QSound::play(":/sounds/xfer-done.wav");
        }

        QApplication::restoreOverrideCursor();
    }
    catch(int)
    {
        QMessageBox::warning(0,tr("Device Link Error"),dev->getLastError().c_str(),QMessageBox::Ok,QMessageBox::NoButton);
        QApplication::restoreOverrideCursor();
        return;
    }

    theMainWindow->getCanvas()->setFadingMessage(tr("Upload tracks finished!"));
}
开发者ID:Nikoli,项目名称:qlandkartegt,代码行数:60,代码来源:CDeviceGarmin.cpp

示例5: open

void CaxaRun::open()
{
	QString fileName = QFileDialog::getExistingDirectory(this, "", "");
	if (!fileName.isEmpty())
	{
		CxXmlHelper helper("");
		string name = fileName.toStdString();
		QTextCodec *c = QTextCodec::codecForName("gb18030");
		if (c) 
		{
			name = c->fromUnicode(fileName).data();
		}

		if (helper.read(name))
		{
			m_knowledges = helper.knowlegdes();
			ui.cb_knowledge->clear();

			std::map<std::string, CxKnowlegdeDesc>::iterator it = m_knowledges.begin();
			while (it != m_knowledges.end())
			{  
				ui.cb_knowledge->addItem(QString::fromStdString(it->second.m_strName.c_str()));
				it++;
			}
		}
	}
}
开发者ID:cxwangwc,项目名称:Rule,代码行数:27,代码来源:caxarun.cpp

示例6: if

void XmlSync::processEntryType05(QDomElement &parentNode, QByteArray *data)
{
    QDomElement entryNode = parentNode.firstChildElement();
    QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");

    while(!entryNode.isNull())
    {
        if(entryNode.tagName() == QString("text"))
        {
            QDomElement originalNode;
            QString originalText;

            GET_NODE(entryNode, "original", originalNode);
            GET_NODE_TEXT(originalNode, originalText);

            data->append(codec->fromUnicode(originalText));
        }
        else if (entryNode.tagName() == QString("ctrl"))
        {
            QString ctrlString;

            ATTRIBUTE_TO_STRING_NOT_EMPTY(entryNode, "value", ctrlString);
            data->append(ctrlString);
        }
        else
        {
            fatalExit("Unknown tag (not 'text' or 'ctrl')");
        }

        entryNode = entryNode.nextSiblingElement();
    }
}
开发者ID:bureg,项目名称:amg-codec-tool,代码行数:32,代码来源:xmlsync.cpp

示例7: readRecentFiles

//------------------------------------------------------------------------------------
void readRecentFiles(QSettings& settings)
{
    int recentFileCount = settings.value("recentfiles/count").toInt();
    Ogitors::UTFStringVector recentList;
    recentList.clear();
    for(int i = 0;i < recentFileCount;i++)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-16");
        QString value = settings.value(QString("recentfiles/entry%1").arg(i)).toString();

        if(!QFile::exists(value))
            continue;

        QByteArray encodedString = codec->fromUnicode(value);

        Ogre::ushort *data = (Ogre::ushort*)encodedString.data();
        data++;

        Ogre::UTFString retStr(data,(encodedString.size() / 2) - 1);

        recentList.push_back(retStr);
    }

    Ogitors::OgitorsRoot::getSingletonPtr()->InitRecentFiles(recentList);
}
开发者ID:rulk,项目名称:eyerie-ogitor-fork,代码行数:26,代码来源:main.cpp

示例8: exec

bool NCSqlQuery::exec( const QString & qs )
{
	bool ok = false;
	QTextCodec* codec = QTextCodec::codecForName(NCSQL_DEFAULTCODEC);
	
	if ( qs.isEmpty() )
		ok = QSqlQuery::exec();
	else
		ok = QSqlQuery::exec( (const char*)(codec->fromUnicode( qs )) );

	if ( !ok )
		logSqlError( qs, getErrorMsg() );
		
	if ( isActive() )
		saveColumns();
	else
		ok = false;
		
	//recinfo = sqlquery->driver()->recordInfo( *sqlquery );

	#ifdef NCSQL_ALWAYSLOG
		logSqlError( qs, "OK." );
	#endif

		
	#ifdef NCSQL_DEBUG_ON
		qDebug( "**************************************" );
		qDebug( "Execute NCSqlQuery::exec(...)" );
		qDebug( "**************************************" );
		qDebug( "%s", qPrintable(qs) );
		qDebug( "**************************************" );
	#endif
		
	return ok;
}
开发者ID:bagonzalez,项目名称:ncreport,代码行数:35,代码来源:ncsqlquery.cpp

示例9: gbk_2_utf8

QString gbk_2_utf8(const QString &in)
{
    QTextCodec *gbk = QTextCodec::codecForName("gbk");
    //QTextCodec *utf8 = QTextCodec::codecForName("uft8");

    return gbk->toUnicode(gbk->fromUnicode(in));
}
开发者ID:houbin,项目名称:recipes,代码行数:7,代码来源:transform_encode.cpp

示例10: drawText

void ZebraPaintEngine::drawText ( const QPointF &p, const QString & text, const QFont &font )
{
  QTransform transform = painter()->worldTransform();

  int xInDots = (int)(transform.dx());
  int yInDots = (int)(transform.dy());

  int carHeight = (font.pointSize() * resolution()) / 72;
  const int minSize = 10;
  if(carHeight < minSize) {
    carHeight = minSize;
  }
  int carWidth = qRound((carHeight * 15.0) / 28.0); // fixed width/height ratio for the scalable A0 font

  QString rotation = transformRotationCmd();
  if(rotation == rotation90Cmd()) {
    xInDots -= carHeight;
  }
  else if(rotation == rotation180Cmd()) {
    yInDots -= carHeight;
    xInDots -= (carWidth * text.length());
  }
  else if(rotation == rotation270Cmd()) {
    yInDots -= (carWidth * text.length());
  }

  QString output = QString(m_CmdPrefix + "FO%1,%2" + m_CmdPrefix + "FW%3").arg(xInDots).arg(yInDots).arg(rotation);
  output += QString(m_CmdPrefix + "A0,%1,0" + m_CmdPrefix + "FD" + text + m_CmdPrefix + "FS\n").arg(carHeight);

  QTextCodec *codec = QTextCodec::codecForName("IBM 850");
  m_printBuffer.append(codec->fromUnicode(output));
}
开发者ID:bunhin,项目名称:openrpt,代码行数:32,代码来源:zebrapaintengine.cpp

示例11: PDFDoc

DocumentPDF::DocumentPDF(const QString& _name)
{
#ifdef WIN32
    int size = _name.size();
    wchar_t* buffer = new wchar_t[size];
    _name.toWCharArray(buffer);
    m_xpdfDoc = new PDFDoc(buffer, size);
    delete [] buffer;
#elif defined __unix__

    QTextCodec* codec = QTextCodec::codecForName("UTF-8");

    QByteArray array = codec->fromUnicode(_name);

    const_c_str_t name = array.data();
    GString* filename = new GString( name );
    m_xpdfDoc = new PDFDoc(filename);    
#endif
    m_valid = m_xpdfDoc->isOk();
    if (m_valid)
    {
        m_numberOfPages = m_xpdfDoc->getNumPages();
        mp_thumbonails = new QList<QImage*>();
        m_pageNumber = 1;
        m_pageZoom = 1;
        mp_currentPage = NULL;
    }
}
开发者ID:pavelliavonau,项目名称:qxpdf,代码行数:28,代码来源:documentpdf.cpp

示例12: workChanged

void doctorChangeDialog::workChanged()
{
    //QTextCodec* codec = QTextCodec::codecForName("Windows-1251");
    QTextCodec *codec = QTextCodec::codecForName("CP866");
    QByteArray work = codec->fromUnicode( ui.workHours->text() );
    strncpy_s( doc->priem, work.constData(), 50 );
}
开发者ID:artem-bochkarev,项目名称:alexandras_task,代码行数:7,代码来源:doctorChangeDialog.cpp

示例13: dolgnostChanged

void doctorChangeDialog::dolgnostChanged()
{
    //QTextCodec* codec = QTextCodec::codecForName("Windows-1251");
    QTextCodec *codec = QTextCodec::codecForName("CP866");
    QByteArray dolgnost = codec->fromUnicode( ui.speciality->text() );
    strncpy_s( doc->dolgnost, dolgnost.constData(), 50 );
}
开发者ID:artem-bochkarev,项目名称:alexandras_task,代码行数:7,代码来源:doctorChangeDialog.cpp

示例14: fioChanged

void doctorChangeDialog::fioChanged()
{
    //QTextCodec* codec = QTextCodec::codecForName("Windows-1251");
    QTextCodec *codec = QTextCodec::codecForName("CP866");
    QByteArray fio = codec->fromUnicode( ui.fio->text() );
    strncpy_s( doc->fio, fio.constData(), 50 );
}
开发者ID:artem-bochkarev,项目名称:alexandras_task,代码行数:7,代码来源:doctorChangeDialog.cpp

示例15: sizeof

QVector<QString> IndexedEdictFile::findMatches( const QString &query ) const
{
  QVector<QString> results;
  if( ! m_valid )
  {
    return results;
  }

  QTextCodec *codec = QTextCodec::codecForName( "eucJP" );
  if( ! codec )
  {
    return results;
  }

  QByteArray searchString = codec->fromUnicode( query );
  int indexSize = m_indexFile.size() / sizeof( uint32_t );
  int dictSize  = m_dictFile.size() / sizeof( unsigned char );

  int matchLocation = findFirstMatch( searchString );
  QByteArray currentWord = lookupDictLine( ++matchLocation );
  if( matchLocation == 0 )
  {
    return results;
  }

  QVector<uint32_t> possibleHits;

  do
  {
    currentWord = lookupDictLine( ++matchLocation );
    int i = 0;
    while( lookupDictChar( m_indexPtr[ matchLocation - 1 ] + i - 2 ) != 0x0A )
    {
      --i;
    }
    possibleHits.push_back( m_indexPtr[ matchLocation - 1 ] + i - 1 );
  } while( matchLocation < indexSize && 0 == equalOrSubstring( searchString, currentWord ) );

  if( possibleHits.size() <= 0 )
  {
    return results;
  }

  qSort( possibleHits );
  uint32_t last = 0;

  foreach( uint32_t it, possibleHits )
  {
    if(last != it)
    {
      last = it;
      results.push_back( codec->toUnicode( lookupFullLine( it ) ) );
    }
  }

  return results;
}
开发者ID:KDE,项目名称:kiten,代码行数:57,代码来源:indexededictfile.cpp


注:本文中的QTextCodec::fromUnicode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。