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


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

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


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

示例1: translate

QString MIMECodec::translate(const QCString &name)
{
  QString output;

  if (!name.isEmpty()) {
    int begin = -1, end = -1, pos = -1;
    QCString translated_name(name);
    QCString charset, encoding;
    QCString token;
    bool sem(true);

    while (sem) {
      begin = translated_name.find("=?", 0);

      if (begin != -1)
        end = translated_name.find("?=", begin + 2);
      else
        end = -1;

      if (end != -1) {
        output += QString::fromAscii(translated_name.left(begin));
        token = translated_name.mid(begin + 2, end - begin - 2);

        pos = token.find('?');
        charset = token.left(pos);
        token.remove(0, pos + 1);

        pos = token.find('?');
        encoding = token.left(pos);
        token.remove(0, pos + 1);
        encoding = encoding.upper();

        if (encoding == "Q") {
          encoding = "quoted-printable";
        } else if (encoding == "B") {
          encoding = "base64";
        } else {
          encoding = "none";
        }
        token = decode(token, encoding);

        QTextCodec *codec = QTextCodec::codecForName(charset);
        if (codec) {
          output += codec->toUnicode(token);
        } else {
          if (charset.lower() == "utf-8") {
            output += QString::fromUtf8(token);
          } else if (charset.lower() == "us-ascii") {
            output += QString::fromAscii(token);
          }
          // just use something
          else {
            qDebug("Warning: could not find textcodec for %s.", (const char *)charset);
            output += QString::fromLatin1(token);
          }
        }

        translated_name = translated_name.mid(end + 2);
      } else {
        output += QString::fromAscii(translated_name);
        sem = false;
      }
    }
  }

  return output;
}
开发者ID:Miguel-J,项目名称:eneboo-core,代码行数:67,代码来源:mimecodec.cpp

示例2: load

bool DocumentEditor::load(const QString &fileName_) {
	QFile file(fileName_);
	if (!file.open(QFile::ReadOnly)) {
		QMessageBox::warning(this, PACKAGE_NAME,
							 tr("Cannot read file %1:\n%2.")
							 .arg(fileName_)
							 .arg(file.errorString()));
		return false;
	}

	///@todo better charset detection
	char bom[6];
	file.read(bom, 6);
	file.reset();
	detectBOM(bom);

	QString shebang;
	for(uint8_t i = 0; i < 5; i++){
		if(bom[i] == '#'){
			if(bom[i+1] == '!'){
				char line[80];
				file.readLine(line, 80);
				file.reset();
				shebang = line;
			}
		}
	}

	QTextCodec* codec = QTextCodec::codecForName(_codec.toUtf8());
	if(codec == 0) {
		QMessageBox::critical(this, PACKAGE_NAME,
							  tr("Cannot load file %1:\nUnsupported charset %2 !!")
							  .arg(fileName_).arg(_codec));
		return false;
	}

	QApplication::setOverrideCursor(Qt::WaitCursor);

	QString data = codec->toUnicode(file.readAll());
	setText(data);

	_fullPath = fileName_;
	_isNew = false;
	setModified(false);

	if(_autoDetectEol)
		autoDetectEol();
	if(_autoDetectIndent)
		autoDetectIndent();

	//add lexer
	QsciLexer* l = lexer();
	//detach lexer from document before delete it
	setLexer(0);
	if(l != 0) {
		delete l;
		l = 0;
	}
	setLexer(LexerManager::getInstance().getAutoLexer(this, shebang));

	//reload settings for lexer
	Settings settings;
	settings.applyToDocument(this);

	//add it to the watcher
	_watcher.addPath(_fullPath);

	QApplication::restoreOverrideCursor();
	_notified = true;

	return true;
}
开发者ID:jzsun,项目名称:raptor,代码行数:72,代码来源:document_editor.cpp

示例3: slotError

void Process::slotError(QProcess::ProcessError err){
	if (myProcess->exitCode()!=0){

		QTextStream stdErr(stderr);
		QString lang = this->getLocale();

		QTextCodec *codec = QTextCodec::codecForName(lang.toAscii());
		if (!codec){
			stdErr<<"[ee] Can't setup codec for \""<<lang<<"\""<<endl;
			stdErr<<"[ee] Aborting current operation!"<<endl;
			reject();
			return;
		}

		QString string = codec->toUnicode(myProcess->readAllStandardError());

		if (!string.isEmpty()){
			QMessageBox::warning(this, tr("Error"), tr("It seems procces fail.<br><br>Error log:<br>%1").arg(string));
		} else {
			switch (err){
			case 0:
				QMessageBox::warning(this, tr("Error"), tr("Process: The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program."));
				break;
			case 1:
				QMessageBox::warning(this, tr("Error"), tr("Process: The process crashed some time after starting successfully."));
				break;
			case 2:
				QMessageBox::warning(this, tr("Error"), tr("Process: The last waitFor...() function timed out."));
				break;
			case 3:
				QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to read from the process. For example, the process may not be running."));
				break;
			case 4:
				QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel."));
				break;
			case 5:
				QMessageBox::warning(this, tr("Error"), tr("Process: An unknown error occurred. This is the default return value of error()."));
				break;
			}
            reject ();
		}
	} else {
		switch (err){
			case 0:
			QMessageBox::warning(this, tr("Error"), tr("Process: The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program."));
			break;
			case 1:
			QMessageBox::warning(this, tr("Error"), tr("Process: The process crashed some time after starting successfully."));
			break;
			case 2:
			QMessageBox::warning(this, tr("Error"), tr("Process: The last waitFor...() function timed out."));
			break;
			case 3:
			QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to read from the process. For example, the process may not be running."));
			break;
			case 4:
			QMessageBox::warning(this, tr("Error"), tr("Process: An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel."));
			break;
			case 5:
			QMessageBox::warning(this, tr("Error"), tr("Process: An unknown error occurred. This is the default return value of error()."));
			break;
		}
		reject ();
	}
	return;
}
开发者ID:PappBence,项目名称:q4wine,代码行数:66,代码来源:process.cpp

示例4: switch

void        DasmDlg::on_execaction_clicked()
{
    QTextCodec *codec = QTextCodec::codecForLocale();

    QString elffile     = m_ui.ElfName->text().trimmed() ;
    QString param       = m_ui.ActParam->text().trimmed ();
    enum EExcDasmMode actmod = EExcDasmAll;

    switch(m_ui.ActMode->currentIndex() ){
        case 0: actmod  = EExcDasmAll; break;
        case 1: actmod  = param.isEmpty() ? EExcDasmFuncList : EExcDasmFuncMatchList;
                break;
        case 2: actmod  = EExcDasmFuncMatch; break;
        case 3: actmod  = EExcDasmFunc;    break;
        case 4: actmod  = EExcDasmAddr;    break;
        default:    break;
    }

    if( elffile.isEmpty() ){
        QMessageBox::warning( 0 /* Core::ICore::instance()->mainWindow()  */,
                codec->toUnicode("无法执行操作"),
                codec->toUnicode("未指定elf文件名"));
        return ;
    }

    if( param.isEmpty() 
            && (actmod == EExcDasmFuncMatch 
                || actmod == EExcDasmFunc 
                || actmod == EExcDasmAddr ) ){
        QMessageBox::warning( 0 /* Core::ICore::instance()->mainWindow()  */,
                codec->toUnicode("无法执行操作"),
                actmod == EExcDasmAddr ? 
                codec->toUnicode("操作需要传入一个数字类型的参数")
                :codec->toUnicode("操作需要传入字符串参数"));
        return ;
    }

    QString tmp ;
    tmp = QDesktopServices::storageLocation(QDesktopServices::TempLocation)+ "/exc_dasm.txt";

    if( actmod  == EExcDasmAll ){
        QString name = QFileDialog::getSaveFileName(this,
                codec->toUnicode("全部反汇编需要的时间较长,你想把反汇编结果另存到文件吗?"), m_curpath, tr("txt Files (*.txt)"));
        if(!name.isEmpty()) {
            tmp = name;
        }
    }

    FILE    *fp = fopen(tmp.toLatin1().data(),"w+");
    if( !fp ){
        QMessageBox::warning  ( 0 /* Core::ICore::instance()->mainWindow()  */,
                codec->toUnicode("无法执行操作"),
                codec->toUnicode("创建输出文件失败"));
        return ;
    }

    int ret     = Exc_Dasm(fp,elffile.toLatin1().data(),
            actmod,param.toLatin1().data());

    QFile scriptFile;
    fseek(fp,0,SEEK_SET);
    scriptFile.open(fp,QIODevice::ReadOnly);   

    m_ui.textEdit->setPlainText(scriptFile.readAll());
    scriptFile.close();

    if( ret != 0 ){
        QString  err;
        err.sprintf("analyse error code:%d",ret);
        QMessageBox::warning( 0 /* Core::ICore::instance()->mainWindow()  */,
                exc_tr("dasm fail"),
                err);
    }
}
开发者ID:wsue,项目名称:excanalyse,代码行数:74,代码来源:dasmdlg.cpp

示例5: myDecoderFunc

QString myDecoderFunc(const QByteArray &localFileName)
{
    QTextCodec* codec = QTextCodec::codecForName("UTF-8");
    return codec->toUnicode(localFileName);
}
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:5,代码来源:MainGui.cpp

示例6: main

int main(int argc, char *argv[])
{
	SetErrorMode(SEM_NOGPFAULTERRORBOX);
	SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
	SingleApplication a(argc, argv);
	
	if (a.isRunning()) {

		return 0;
	}
	
	char *pFile = NULL;
	QString strFile = "";
	if (argc >= 2)
	{
		pFile = argv[1];
		QTextCodec *textcode = QTextCodec::codecForName("GB18030");
		strFile = textcode->toUnicode(pFile);
	}
#ifndef QT_NO_DEBUG
	showMainDlgNoExcept(a, strFile);
	return 1;

/*	QString appDir = QApplication::applicationDirPath() + "/";
	if (argc <= 1 || strcmp(argv[1], "-s") != 0)
	{

		QProcess::startDetached(appDir + Verify::startExe());
		return 0;

	}*/
#else
#ifdef UKey
	showMainDlgNoExcept(a, strFile);
	return 0;
#else
	AuthorFile=QApplication::applicationDirPath() + "/AuthorFile";
	initDb();
	MD5 md5_toApply;//用于生成申请码

	unsigned char address[1024];

	memset(address, 0, 1024);
#ifndef DISKSN
	if (getLocalMac(address) > 0)
#else
	if (GetHardDriveSerialNumber((char*)address, 1024) > 0)
#endif
	{
		md5_toApply.update((const char *)address);//生成申请码
	}
	else
	{

	}

	if (!Dialog::hasKey())
	{
		Dialog w;
		w.show();
		a.exec();
		exit(0);
	}
	showMainDlgNoExcept(a, strFile);
#endif
#endif 
}
开发者ID:anyboo,项目名称:SPlayer,代码行数:67,代码来源:main.cpp

示例7: slotParse

/** @brief Parse xml-data
 *----------------------------------------------------------------------------*/
void ParseObject::slotParse(const QByteArray &xmlData, const int &feedId,
                            const QDateTime &dtReply, const QString &codecName)
{
  if (mainApp->isSaveDataLastFeed()) {
    QFile file(mainApp->dataDir()  + "/lastfeed.dat");
    file.open(QIODevice::WriteOnly);
    file.write(xmlData);
    file.close();
  }

  qDebug() << "=================== parseXml:start ============================";

  db_.transaction();

  // extract feed id and duplicate news mode from feed table
  parseFeedId_ = feedId;
  QString feedUrl;
  duplicateNewsMode_ = false;
  QSqlQuery q(db_);
  q.setForwardOnly(true);
  q.exec(QString("SELECT duplicateNewsMode, xmlUrl FROM feeds WHERE id=='%1'").arg(parseFeedId_));
  if (q.first()) {
    duplicateNewsMode_ = q.value(0).toBool();
    feedUrl = q.value(1).toString();
  }

  // id not found (ex. feed deleted while updating)
  if (feedUrl.isEmpty()) {
    qWarning() << QString("Feed with id = '%1' not found").arg(parseFeedId_);
    emit signalFinishUpdate(parseFeedId_, false, 0, "0");
    db_.commit();
    return;
  }

  qDebug() << QString("Feed '%1' found with id = %2").arg(feedUrl).arg(parseFeedId_);

  // actually parsing
  feedChanged_ = false;

  bool codecOk = false;
  QString convertData(xmlData);
  QString feedType;
  QDomDocument doc;
  QString errorStr;
  int errorLine;
  int errorColumn;

  QRegExp rx("encoding=\"([^\"]+)",
             Qt::CaseInsensitive, QRegExp::RegExp2);
  int pos = rx.indexIn(xmlData);
  if (pos == -1) {
    rx.setPattern("encoding='([^']+)");
    pos = rx.indexIn(xmlData);
  }
  if (pos > -1) {
    QString codecNameT = rx.cap(1);
    qDebug() << "Codec name (1):" << codecNameT;
    QTextCodec *codec = QTextCodec::codecForName(codecNameT.toUtf8());
    if (codec) {
      convertData = codec->toUnicode(xmlData);
    } else {
      qWarning() << "Codec not found (1): " << codecNameT << feedUrl;
      if (codecNameT.contains("us-ascii", Qt::CaseInsensitive)) {
        QString str(xmlData);
        convertData = str.remove(rx.cap(0)+"\"");
      }
    }
  } else {
    if (!codecName.isEmpty()) {
      qDebug() << "Codec name (2):" << codecName;
      QTextCodec *codec = QTextCodec::codecForName(codecName.toUtf8());
      if (codec) {
        convertData = codec->toUnicode(xmlData);
        codecOk = true;
      } else {
        qWarning() << "Codec not found (2): " << codecName << feedUrl;
      }
    }
    if (!codecOk) {
      codecOk = false;
      QStringList codecNameList;
      codecNameList << "UTF-8" << "Windows-1251" << "KOI8-R" << "KOI8-U"
                    << "ISO 8859-5" << "IBM 866";
      foreach (QString codecNameT, codecNameList) {
        QTextCodec *codec = QTextCodec::codecForName(codecNameT.toUtf8());
        if (codec && codec->canEncode(xmlData)) {
          qDebug() << "Codec name (3):" << codecNameT;
          convertData = codec->toUnicode(xmlData);
          codecOk = true;
          break;
        }
      }
      if (!codecOk) {
        convertData = QString::fromLocal8Bit(xmlData);
      }
    }
开发者ID:Nikoli,项目名称:quite-rss,代码行数:98,代码来源:parseobject.cpp

示例8: treewalkFile

int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
{
    if( ! file ) return -1;

    QTextCodec::ConverterState utf8State;
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    Q_ASSERT(codec);
    QString fileUtf8 = codec->toUnicode(file->path, qstrlen(file->path), &utf8State);
    QString renameTarget;
    QString key = fileUtf8;

    auto instruction = file->instruction;
    if (utf8State.invalidChars > 0 || utf8State.remainingChars > 0) {
        qWarning() << "File ignored because of invalid utf-8 sequence: " << file->path;
        instruction = CSYNC_INSTRUCTION_IGNORE;
    } else {
        renameTarget = codec->toUnicode(file->rename_path, qstrlen(file->rename_path), &utf8State);
        if (utf8State.invalidChars > 0 || utf8State.remainingChars > 0) {
            qWarning() << "File ignored because of invalid utf-8 sequence in the rename_path: " << file->path << file->rename_path;
            instruction = CSYNC_INSTRUCTION_IGNORE;
        }
        if (instruction == CSYNC_INSTRUCTION_RENAME) {
            key = renameTarget;
        }
    }

    // Gets a default-contructed SyncFileItemPtr or the one from the first walk (=local walk)
    SyncFileItemPtr item = _syncItemMap.value(key);
    if (!item)
        item = SyncFileItemPtr(new SyncFileItem);

    if (item->_file.isEmpty() || instruction == CSYNC_INSTRUCTION_RENAME) {
        item->_file = fileUtf8;
    }
    item->_originalFile = item->_file;

    if (item->_instruction == CSYNC_INSTRUCTION_NONE
            || (item->_instruction == CSYNC_INSTRUCTION_IGNORE && instruction != CSYNC_INSTRUCTION_NONE)) {
        item->_instruction = instruction;
        item->_modtime = file->modtime;
    } else {
        if (instruction != CSYNC_INSTRUCTION_NONE) {
            qDebug() << "ERROR: Instruction" << item->_instruction << "vs" << instruction << "for" << fileUtf8;
            Q_ASSERT(!"Instructions are both unequal NONE");
            return -1;
        }
    }

    if (file->file_id && strlen(file->file_id) > 0) {
        item->_fileId = file->file_id;
    }
    if (file->directDownloadUrl) {
        item->_directDownloadUrl = QString::fromUtf8( file->directDownloadUrl );
    }
    if (file->directDownloadCookies) {
        item->_directDownloadCookies = QString::fromUtf8( file->directDownloadCookies );
    }
    if (file->remotePerm && file->remotePerm[0]) {
        item->_remotePerm = QByteArray(file->remotePerm);
    }

    item->_should_update_metadata = item->_should_update_metadata || file->should_update_metadata;

    /* The flag "serverHasIgnoredFiles" is true if item in question is a directory
     * that has children which are ignored in sync, either because the files are
     * matched by an ignore pattern, or because they are  hidden.
     *
     * Only the information about the server side ignored files is stored to the
     * database and thus written to the item here. For the local repository its
     * generated by the walk through the real file tree by discovery phase.
     *
     * It needs to go to the sync journal becasue the stat information about remote
     * files are often read from database rather than being pulled from remote.
     */
    if( remote ) {
        item->_serverHasIgnoredFiles    = (file->has_ignored_files > 0);
    }

    // record the seen files to be able to clean the journal later
    _seenFiles.insert(item->_file);
    if (!renameTarget.isEmpty()) {
        // Yes, this record both the rename renameTarget and the original so we keep both in case of a rename
        _seenFiles.insert(renameTarget);
    }

    if (remote && file->remotePerm && file->remotePerm[0]) {
        _remotePerms[item->_file] = file->remotePerm;
    }

    switch(file->error_status) {
    case CSYNC_STATUS_OK:
        break;
    case CSYNC_STATUS_INDIVIDUAL_IS_SYMLINK:
        item->_errorString = tr("Symbolic links are not supported in syncing.");
        break;
    case CSYNC_STATUS_INDIVIDUAL_IGNORE_LIST:
        item->_errorString = tr("File is listed on the ignore list.");
        break;
    case CSYNC_STATUS_INDIVIDUAL_IS_INVALID_CHARS:
        item->_errorString = tr("Filename contains invalid characters that can not be synced cross platform.");
//.........这里部分代码省略.........
开发者ID:wkarl,项目名称:client,代码行数:101,代码来源:syncengine.cpp

示例9: loadSNX

TPage loadSNX(QString fname, int cpage) {
	TPage page;
	QFile file(fname);
	if (!file.open(QFile::ReadOnly)) return page;
	TLine line;
	line.type = TL_TEXT;
	QTextCodec* codec = QTextCodec::codecForName("Shift-JIS");

	int count = get4(file);
	int p1 = get4(file);
	int p2,p3;
	int len;

	long dataPos = count * 12 + 8;
	long curPos = 0;
//	long adr = 0;
	char buf[1024];
	char cbuf[1024];
	char* sptr;
	char* dptr;

//	if (dump) printf("; bytecode\n\n");

	while (count > 0) {
		p1 = get4(file);
		p2 = get4(file);
		p3 = get4(file);
		if ((p1 == 0x11) && (p2 == 0x02)) {
			curPos = file.pos();
			file.seek(dataPos + p3);
			len = get4(file);
			file.read(buf,len);
			file.seek(curPos);
			sptr = buf;
			dptr = buf;
			if (*sptr == 0x01) {
				sptr += 3;
			}
			while(1) {
				if ((*sptr > 0x00) && (*sptr < 0x04)) {
					sptr++;
				} else {
					*dptr = *sptr;
					if (*dptr == 0x00) break;
					dptr++;
					sptr++;
				}
			}
		}
		if (p1 == 0x0d) {
			if (p2 == 0x012) {
				sprintf(cbuf,"[ %s ]",buf);
				//fwrite(cbuf,strlen(cbuf),1,ofile);
				line.src.name.clear();
				line.src.text = codec->toUnicode(cbuf);
				page.text.append(line);
			} else if (p2 == 0x2c) {
				sprintf(cbuf,"%s\n",buf);
				//fwrite(cbuf,strlen(cbuf),1,ofile);
				line.src.name.clear();
				line.src.text = codec->toUnicode(buf);
				normLine(line);
				page.text.append(line);
			}
		}
//		if (dump) printf("\n");
		count--;
	}

	return page;
}
开发者ID:samstyle,项目名称:transtext,代码行数:71,代码来源:snx.cpp

示例10: mimeConvertToFormat

QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &data, const QString &format,
                                       QVariant::Type requestedType, const QByteArray &encoding)
{
    QString atomName = mimeAtomToString(connection, a);
//    qDebug() << "mimeConvertDataToFormat" << format << atomName << data;

    if (!encoding.isEmpty()
        && atomName == format + QLatin1String(";charset=") + QString::fromLatin1(encoding)) {

#ifndef QT_NO_TEXTCODEC
        if (requestedType == QVariant::String) {
            QTextCodec *codec = QTextCodec::codecForName(encoding);
            if (codec)
                return codec->toUnicode(data);
        }
#endif

        return data;
    }

    // special cases for string types
    if (format == QLatin1String("text/plain")) {
        if (a == connection->atom(QXcbAtom::UTF8_STRING))
            return QString::fromUtf8(data);
        if (a == XCB_ATOM_STRING ||
            a == connection->atom(QXcbAtom::TEXT))
            return QString::fromLatin1(data);
    }

    // special case for uri types
    if (format == QLatin1String("text/uri-list")) {
        if (atomName == QLatin1String("text/x-moz-url")) {
            // we expect this as utf16 <url><space><title>
            // the first part is a url that should only contain ascci char
            // so it should be safe to check that the second char is 0
            // to verify that it is utf16
            if (data.size() > 1 && data.at(1) == 0)
                return QString::fromRawData((const QChar *)data.constData(),
                                data.size() / 2).split(QLatin1Char('\n')).first().toLatin1();
        }
    }

    if (atomName == format)
        return data;

#if 0 // ###
    // special case for images
    if (format == QLatin1String("image/ppm")) {
        if (a == XCB_ATOM_PIXMAP && data.size() == sizeof(Pixmap)) {
            Pixmap xpm = *((Pixmap*)data.data());
            if (!xpm)
                return QByteArray();
            Window root;
            int x;
            int y;
            uint width;
            uint height;
            uint border_width;
            uint depth;

            XGetGeometry(display, xpm, &root, &x, &y, &width, &height, &border_width, &depth);
            XImage *ximg = XGetImage(display,xpm,x,y,width,height,AllPlanes,depth==1 ? XYPixmap : ZPixmap);
            QImage qimg = QXlibStatic::qimageFromXImage(ximg);
            XDestroyImage(ximg);

            QImageWriter imageWriter;
            imageWriter.setFormat("PPMRAW");
            QBuffer buf;
            buf.open(QIODevice::WriteOnly);
            imageWriter.setDevice(&buf);
            imageWriter.write(qimg);
            return buf.buffer();
        }
    }
#endif
    return QVariant();
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:77,代码来源:qxcbmime.cpp

示例11: GetDriverInfoFromWeb

// 和甜椒的服务通讯
bool SubmitData::GetDriverInfoFromWeb(GetDriverParam param,DriverInfo &driver)
{
	QMap<QString,QString> sendData = param.toMap();

	CommSendData2Web(sendData,PackageService,GetDriver,true);

	QTextCodec *tc = QTextCodec::codecForName("UTF-8");
	QByteArray ba = http->readAll();
	QString str = tc->toUnicode(ba);

	if (http!=NULL)
		delete http;
	if (loop!=NULL)
		delete loop;
	QDomDocument document; 
	if (!document.setContent(str))
	{
		driver.Clear();
		return false;  
	}  
	QDomElement root = document.documentElement();  

	QString isSuccess=getXmlValue(root,"IsSuccess");
	if (isSuccess=="") 
	{
		driver.Clear();
		qDebug() << "network report infomation error\n\n";
		return false;
	}
	else if (isSuccess.toLower()=="false")
	{
		driver.Clear();
		driver.DriverId = -2;
		qDebug() << "backstage not set driver\n\n";
		return false;
	}
	QString deviceId=getXmlValue(root,"DeviceID");
	driver.DriverId=deviceId.toLongLong();
	driver.Url=getXmlValue(root,"Url");
	driver.MD5=getXmlValue(root,"MD5");
	QString tmpDeviceType=getXmlValue(root,"DeviceType");

	if (tmpDeviceType=="INI")
		driver.DrvierType=1;
	else
		driver.DrvierType=2;

	driver.DriverName=getXmlValue(root,"MachineName");
	driver.StartFile=getXmlValue(root,"StartFile");
	driver.Version=getXmlValue(root,"Version").toInt();
	QString s= getXmlValue(root, "IsDeviceCollect");
	driver.isDeviceCollect= s == "true" ? true : false;
	driver.deviceStatue = getXmlValue(root, "DeviceStatue").toInt();
	QString strType = getXmlValue(root, "DataType");
	bool deviceType = strType == "true" ? true : false;
	if (deviceType) 
	{
		qDebug() << "exact driver recognition\n\n";
	}
	else 
	{
		qDebug() << "general driver recognition\n\n";
	}
	driver.DataType = deviceType;

	return true;
}
开发者ID:zfuke164345,项目名称:MyProject,代码行数:68,代码来源:SubmitData.cpp

示例12: on_mIBFTreeView_selectionChanged_triggered

void QuaMainWindow::on_mIBFTreeView_selectionChanged_triggered(const QModelIndex & current, const QModelIndex & previous)
{
    if ( mQuaTextEdit->document()->isModified() )
    {
        mQuaTextEdit->IBFSaveToFile(mQuaTextEdit->windowFilePath());
    }

    if ( !mIBFFileSystemModel->fileInfo(current).isFile() )
    {
        const bool wasBlocked = mQuaTextEdit->blockSignals(true);

        mQuaTextEdit->clear();
        mQuaTextEdit->setEnabled(false);

        mQuaTextEdit->blockSignals(wasBlocked);

        return;
    }

    QString tFileName = mIBFFileSystemModel->fileInfo(current).absoluteFilePath();

    if ( tFileName.isEmpty() )
    {
        return;
    }

    if ( !QFile::exists(tFileName) )
    {
        return;
    }

    QFile tFile(tFileName);

    if ( !tFile.open(QFile::ReadOnly) )
    {
        return;
    }

    QByteArray tByteArray = tFile.readAll();
    QTextCodec * tTextCodec = Qt::codecForHtml(tByteArray);

    QString tString = tTextCodec->toUnicode(tByteArray);

    const bool wasBlocked = mQuaTextEdit->blockSignals(true);

    if ( Qt::mightBeRichText(tString) )
    {
        mQuaTextEdit->setHtml(tString);
    }
    else
    {
        tString = QString::fromLocal8Bit(tByteArray);
        mQuaTextEdit->setPlainText(tString);
    }

    mQuaTextEdit->blockSignals(wasBlocked);

    mQuaTextEdit->setWindowFilePath(tFileName);
    mQuaTextEdit->setEnabled(true);

}
开发者ID:QuaIBF,项目名称:QuaNotebook,代码行数:61,代码来源:QuaMainWindow.cpp


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