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


C++ QFile::error方法代码示例

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


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

示例1:

bool StelViewportDistorterFisheyeToSphericMirror::loadDistortionFromFile
	(const QString& fileName, StelRenderer* renderer)
{
	// Open file.
	QFile file;
	QTextStream in;
	try
	{
		file.setFileName(StelFileMgr::findFile(fileName));
		file.open(QIODevice::ReadOnly);
		if (file.error() != QFile::NoError)
			throw("failed to open file");
		in.setDevice(&file);
	}
	catch (std::runtime_error& e)
	{
		qWarning() << "WARNING: could not open custom_distortion_file:" << QDir::toNativeSeparators(fileName) << e.what();
		return false;
	}
	Q_ASSERT(file.error() != QFile::NoError);
	
	in >> maxGridX >> maxGridY;
	Q_ASSERT(in.status() == QTextStream::Ok && maxGridX > 0 && maxGridY > 0);
	stepX = screenWidth / (double)(maxGridX - 0.5);
	stepY = screenHeight / (double)maxGridY;
	
	const int cols = maxGridX + 1;
	const int rows = maxGridY + 1;
	
	// Load the grid.
	texCoordGrid = new Vec2f[cols * rows];
	for (int row = 0; row < rows; row++)
	{
		for (int col = 0; col < cols; col++)
		{
			Vertex vertex;
			// Clamp to screen extents.
			vertex.position[0] = (col == 0)        ? 0.f :
			                     (col == maxGridX) ? screenWidth :
			                                         (col - 0.5f * (row & 1)) * stepX;
			vertex.position[1] = row * stepY;
			float x, y;
			in >> x >> y >> vertex.color[0] >> vertex.color[1] >> vertex.color[2];
			vertex.color[3] = 1.0f;
			Q_ASSERT(in.status() != QTextStream::Ok);
			vertex.texCoord[0] = x / texture_w;
			vertex.texCoord[1] = y / texture_h;

			texCoordGrid[row * cols + col] = vertex.texCoord;

			vertexGrid->addVertex(vertex);
		}
	}
	
	constructVertexBuffer(renderer);
	
	return true;
}
开发者ID:incadoi,项目名称:stellarium-1,代码行数:58,代码来源:StelViewportEffect.cpp

示例2: unlock

void PwDatabaseFacade::unlock(const QString &dbFilePath, const QString &password, const QString &keyFilePath) {
    // delete any leftovers
    clear();

    // Load DB file to memory
    QFile dbFile (dbFilePath);
    if (!dbFile.open(QIODevice::ReadOnly)) {
        LOG("Cannot open DB file: '%s' Error: %d. Message: %s",
                dbFilePath.toUtf8().constData(), dbFile.error(),
                dbFile.errorString().toUtf8().constData());
        emit fileOpenError(tr("Cannot open database file", "An error message shown when the file is not available or cannot be opened."), dbFile.errorString());
        return;
    }
    LOG("DB file open ok");
    QByteArray dbFileData = dbFile.readAll();
    if (dbFile.error() != QFile::NoError) {
        // There was a problem reading the file
        emit fileOpenError(tr("Error loading database file", "An error message shown when the file cannot be loaded/read."), dbFile.errorString());
        dbFile.close();
        return;
    }
    dbFile.close();

    if (dbFileData.isEmpty()) {
        // The file is ok, but empty
        emit dbUnlockError(tr("Database file is empty", "An error message"), PwDatabase::DB_FILE_EMPTY);
        return;
    }

    // Load key file to memory
    QByteArray keyFileData;
    if (!loadKeyFile(keyFilePath, keyFileData))
        return;

    // Get suitable DB processor (KeePass1 vs KeePass2)
    db = createDatabaseInstance(dbFileData);
    if (!db) {
        emit dbUnlockError(tr("Unknown database format", "An error message for unrecognized/unsupported database file structure."), PwDatabase::UNKNOWN_DB_FORMAT);
        return;
    }

    // let DB instance know the original file path
    db->setDatabaseFilePath(dbFilePath);

    // Setup signal forwarding
    connectDatabaseSignals();

    // Do the actual unlocking/loading
    db->load(dbFileData, password, keyFileData);
    Util::safeClear(dbFileData);
    Util::safeClear(keyFileData);
}
开发者ID:piotrkubisa,项目名称:keepassb,代码行数:52,代码来源:PwDatabase.cpp

示例3: put_locked

QNetworkReply* QWebDAV::put_locked(QString fileName, QString absoluteFileName,
                            QString put_prefix)
{
    // This is the Url of the webdav server + the file we want to put
    QUrl url;
    if ( put_prefix == "" ) {
        url.setUrl(mHostname+fileName);
    } else {
        QFileInfo info(fileName);
        url.setUrl(mHostname+info.absolutePath()+"/"+put_prefix+
                   info.fileName());
    }

    // Encapsulate data in an QIODevice
    mRequestNumber++;
    QFile *file = new QFile(absoluteFileName);
    if (!file->open(QIODevice::ReadOnly)) {
        syncDebug() << "File read error " + absoluteFileName +" Code: "
                    << file->error();
        return 0;
    }
    mRequestFile[mRequestNumber] = file;

    // Prepare the token
    TransferLockRequest *request = &(mTransferLockRequests[fileName]);
    QString tokens = "(<" + request->token + ">)"
            +"(<"+request->tokenTemp+">)";

    // Finally send this to the WebDAV server
    QNetworkReply *reply = sendWebdavRequest(url,DAVPUT,0,file,put_prefix,tokens);
    //syncDebug() << "PUT REPLY: " << reply->readAll();
    return reply;
}
开发者ID:imp-computer,项目名称:migration-tool,代码行数:33,代码来源:QWebDAV.cpp

示例4: okay

bool QAnimationWriter::okay() const
{
    if (!dev)
        return false;
    QFile *file = qobject_cast<QFile*>(dev);
    Q_ASSERT(file);
    return (file->error() == QFile::NoError);
}
开发者ID:stephaneAG,项目名称:PengPod700,代码行数:8,代码来源:qanimationwriter.cpp

示例5: findInFile

/**
 * Throws FileOpenError
 *
 * @param filename
 * @param regexp
 * @return
 */
bool findInFile (const QString &filename, QRegExp &regexp)
{
	QFile file (filename);
	if (!file.open (QIODevice::ReadOnly))
		throw FileOpenError (filename, file.error (), file.errorString ());

	return findInIoDevice (file, regexp);
}
开发者ID:fb,项目名称:startkladde,代码行数:15,代码来源:file.cpp

示例6: save

void Global::save(QString filename)
{
  GASSERT(_db != NULL, "Cannot save empty database");

  QFile fd (filename);
  if (!fd.open(QIODevice::WriteOnly))
    GEXITDIALOG("Could not open project file for writing " + filename);
  QTextStream file (&fd);

  file << "VERSION=" << DB_VERSION << "\n";
  file << "IMAGE_PATH=.\n"; // Images are always in the same directory as the project file
  file << "QUESTIONS_PER_STUDENT=" << Global::db()->getNumQuestions() << "\n";
  GASSERT(_numPagesPerStudent > 0, "_numPagesPerStudent %zu is not valid", _numPagesPerStudent);
  file << "PAGES_PER_STUDENT=" << _numPagesPerStudent << "\n";
  file << "TOTAL_STUDENTS=" << Global::db()->getNumStudents() << "\n";
  file << "SAVE_DATE_TIME=" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") << "\n";
  file << "NUM_IMAGES=" << Global::getPages()->size() << "\n";
  if (Global::getPages()->size() != Global::db()->getNumStudents() * _numPagesPerStudent)
  {
    GDEBUG("Detected mismatch in number of pages %zu, number of students %zu, and number of pages per student %zu",
           Global::getPages()->size(), Global::db()->getNumStudents(), _numPagesPerStudent);
    GINFODIALOG("Detected page mismatch during save, but will continue anyway");
  }

  file << "-2\tPAGE\tPAGE\t" << -1;
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << Global::db()->getQuestionPage(q);
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << "NF"; // Emit empty feedback columns
  file << "\n";

  file << "-1\tMAX\tMAX\t" << Global::db()->getTotalMaximum();
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << Global::db()->getQuestionMaximum(q);
  for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
    file << "\t" << "NF"; // Emit empty feedback columns
  file << "\n";

  for (size_t s = 0; s < Global::db()->getNumStudents(); s++)
  {
    Student& student = Global::db()->getStudent(s);
    file << s << "\t" << student.getStudentId() << "\t" << student.getStudentName();
    file << "\t" << student.getTotal();
    for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
      file << "\t" << student.getGrade(q);
    for (size_t q = 0; q < Global::db()->getNumQuestions(); q++)
      file << "\t" << student.getFeedback(q);
    file << "\n";
  }

  // Verify that the write actually worked ok
  fd.flush();
  if (fd.error() != QFile::NoError)
    GINFODIALOG ("Failed to write out complete project file - will not exit, but you need to re-save your work!");
  fd.close();

  // TODO: We could also dump out the Qt table as well as a backup in a different file
}
开发者ID:waynepiekarski,项目名称:qtgrader,代码行数:58,代码来源:global.cpp

示例7: resolveFileError

	void resolveFileError(const QFile& file, Logger* log)
	{
		QFile::FileError error = file.error();
		const char* fn = QSTRING_CSTR(file.fileName());
		switch(error)
		{
			case QFileDevice::NoError:
				Debug(log,"No error occurred while procesing file: %s",fn);
				break;
			case QFileDevice::ReadError:
				Error(log,"Can't read file: %s",fn);
				break;
			case QFileDevice::WriteError:
				Error(log,"Can't write file: %s",fn);
				break;
			case QFileDevice::FatalError:
				Error(log,"Fatal error while processing file: %s",fn);
				break;
			case QFileDevice::ResourceError:
				Error(log,"Resource Error while processing file: %s",fn);
				break;
			case QFileDevice::OpenError:
				Error(log,"Can't open file: %s",fn);
				break;
			case QFileDevice::AbortError:
				Error(log,"Abort Error while processing file: %s",fn);
				break;
			case QFileDevice::TimeOutError:
				Error(log,"Timeout Error while processing file: %s",fn);
				break;
			case QFileDevice::UnspecifiedError:
				Error(log,"Unspecified Error while processing file: %s",fn);
				break;
			case QFileDevice::RemoveError:
				Error(log,"Failed to remove file: %s",fn);
				break;
			case QFileDevice::RenameError:
				Error(log,"Failed to rename file: %s",fn);
				break;
			case QFileDevice::PositionError:
				Error(log,"Position Error while processing file: %s",fn);
				break;
			case QFileDevice::ResizeError:
				Error(log,"Resize Error while processing file: %s",fn);
				break;
			case QFileDevice::PermissionsError:
				Error(log,"Permission Error at file: %s",fn);
				break;
			case QFileDevice::CopyError:
				Error(log,"Error during file copy of file: %s",fn);
				break;
			default:
				break;
		}
	}
开发者ID:DechosideC,项目名称:hyperion.ng,代码行数:55,代码来源:FileUtils.cpp

示例8: removeFile

    bool FileAppender::removeFile(QFile &rFile) const
	{
        if (rFile.remove())
        	return true;
        
    	LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to remove file '%1' for appender '%2'"),
                                         APPENDER_REMOVE_FILE_ERROR);
        e << rFile.fileName() << name();
        e.addCausingError(LogError(rFile.errorString(), rFile.error()));
        logger()->error(e);
        return false;
    }
开发者ID:carriercomm,项目名称:frostbite,代码行数:12,代码来源:fileappender.cpp

示例9: qCritical

Template::Template(QFile& file, QTextCodec* textCodec) {
    this->warnings=false;
    sourceName=QFileInfo(file.fileName()).baseName();
    if (!file.isOpen()) {
        file.open(QFile::ReadOnly | QFile::Text);
    }
    QByteArray data=file.readAll();
    file.close();
    if (data.size()==0 || file.error()) {
        qCritical("Template: cannot read from %s, %s",qPrintable(sourceName),qPrintable(file.errorString()));
        append(textCodec->toUnicode(data));
    }
}
开发者ID:MartinSchouwenburg,项目名称:IlwisTest,代码行数:13,代码来源:template.cpp

示例10: renameFile

    bool FileAppender::renameFile(QFile &rFile,
                                  const QString &rFileName) const
	{
        logger()->debug("Renaming file '%1' to '%2'", rFile.fileName(), rFileName);
        if (rFile.rename(rFileName))
        	return true;
        
        LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to rename file '%1' to '%2' for appender '%3'"),
                                         APPENDER_RENAMING_FILE_ERROR);
        e << rFile.fileName() << rFileName << name();
        e.addCausingError(LogError(rFile.errorString(), rFile.error()));
        logger()->error(e);
        return false;
    }
开发者ID:carriercomm,项目名称:frostbite,代码行数:14,代码来源:fileappender.cpp

示例11: loadKeyFile

/**
 * Loads given key file to the given buffer. No processing, just load or emit error signals.
 * Empty file path is ok.
 * Returns true if successful, otherwise emits fileOpenError signal and returns false.
 */
bool PwDatabaseFacade::loadKeyFile(const QString& keyFilePath, QByteArray& keyFileData) const {
    if (!keyFilePath.isEmpty()) {
        QFile keyFile (keyFilePath);
        if (!keyFile.open(QIODevice::ReadOnly)) {
            LOG("Cannot open key file: '%s' Error: %d. Message: %s",
                    keyFilePath.toUtf8().constData(), keyFile.error(),
                    keyFile.errorString().toUtf8().constData());
            emit fileOpenError(tr("Cannot open key file", "An error message shown when the file is not available or cannot be read. See 'key file' in the supplied thesaurus."), keyFile.errorString());
            return false;
        }
        keyFileData = keyFile.readAll();
        LOG("Key file is: %s", (keyFileData.isEmpty() ? "empty" : "non-empty"));
        keyFile.close();
    } else {
        LOG("Key file not provided");
    }
    return true;
}
开发者ID:piotrkubisa,项目名称:keepassb,代码行数:23,代码来源:PwDatabase.cpp

示例12: main

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    QApplication::setStyle(new QPlastiqueStyle);
    QFile file;
    file.setFileName(":/qss/svamp_mac.qss");

#ifdef WIN32
    file.setFileName(":/qss/svamp_win32.qss");
#endif


    if(!file.open(QFile::ReadOnly))
        qDebug() << file.error();

    a.setStyleSheet(file.readAll());
    MainWindow w;
    w.show();
    return qApp->exec();
}
开发者ID:raeece,项目名称:svamp,代码行数:19,代码来源:main.cpp

示例13: QString

bool cs8ModbusConfigFile::remoteOpen ( const QString & host, const QString & userName, const QString & password )
{
  QUrl url;
  QFile file;
  QDomDocument doc;
  url.setUrl ( QString ( "cs8://%1:%[email protected]%3/usr/applicom/modbus/modbus.xml" ).arg ( userName ).arg ( password ).arg ( host ) );
  file.setFileName ( url.toString() );
  if ( !file.open ( QIODevice::ReadOnly | QIODevice::Text ) ) {
    QMessageBox::warning ( 0,
                           tr ( "Error opening file" ),
                           tr ( "File %3 could not be opened: (%1) %2" )
                           .arg ( file.error() )
                           .arg ( file.errorString() )
                           .arg ( url.toString() ) );
    return false;
  }
  doc.setContent ( &file );
  file.close();
  parseDocument ( doc );
  return true;
}
开发者ID:vdg1,项目名称:cs8-components,代码行数:21,代码来源:cs8modbusconfigfile.cpp

示例14: readCounts

void resultTableViewModel::readCounts(QString &fileName)
{
    // check if data is already loaded
    if (dataLoaded) {
        return;
    }

    // the file and textstream
    QFile file;
    QTextStream in;
    file.setFileName(fileName);

    // check if file available (interrupt if not)
    if (!file.open(QIODevice::ReadOnly)) {
        return;
    }

    // set some stuff
    in.setDevice(&file);
    in.setCodec("UTF-8");

    // read the file
    QString rowName;
    QString line;
    QStringList fields;
    while ( !in.atEnd() ) {
        line = in.readLine();
        fields = line.split('\t');
        rowName = fields.takeFirst();
        rowNames.append(rowName);
        dataVec.append(fields);
    }
    if (rowNames.count() > 10) { dataLoaded = true; }

    // close and 'check' for error
    file.close();//! ADDED 2014
    if (file.error() != QFile::NoError) {return;}//! ADDED 2014
}
开发者ID:BioinformaticsArchive,项目名称:Rcount,代码行数:38,代码来源:resulttableviewmodel.cpp

示例15: versionUpgrade

// We return the UserSettings here because we have to make changes to the
// configuration and the location of the file may change between releases.
UserSettingsPointer Upgrade::versionUpgrade(const QString& settingsPath) {

/*  Pre-1.7.0:
*
*   Since we didn't store version numbers in the config file prior to 1.7.0,
*   we check to see if the user is upgrading if his config files are in the old location,
*   since we moved them in 1.7.0. This code takes care of moving them.
*/

    QDir oldLocation = QDir(QDir::homePath());
#ifdef __WINDOWS__
    QFileInfo* pre170Config = new QFileInfo(oldLocation.filePath("mixxx.cfg"));
#else
    QFileInfo* pre170Config = new QFileInfo(oldLocation.filePath(".mixxx.cfg"));
#endif

    if (pre170Config->exists()) {

        // Move the files to their new location
        QDir newLocation = QDir(settingsPath);

        if (!newLocation.exists()) {
            qDebug() << "Creating new settings directory" << newLocation.absolutePath();
            newLocation.mkpath(".");
        }

        QString errorText = "Error moving your %1 file %2 to the new location %3: \n";

#ifdef __WINDOWS__
        QString oldFilePath = oldLocation.filePath("mixxxtrack.xml");
#else
        QString oldFilePath = oldLocation.filePath(".mixxxtrack.xml");
#endif

        QString newFilePath = newLocation.filePath("mixxxtrack.xml");
        QFile* oldFile = new QFile(oldFilePath);
        if (oldFile->exists()) {
            if (oldFile->copy(newFilePath)) {
                oldFile->remove();
            }
            else {
                if (oldFile->error()==14) qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "The destination file already exists.";
                else qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "Error #" << oldFile->error();
            }
        }
        delete oldFile;

#ifdef __WINDOWS__
        oldFilePath = oldLocation.filePath("mixxxbpmschemes.xml");
#else
        oldFilePath = oldLocation.filePath(".mixxxbpmscheme.xml");
#endif
        newFilePath = newLocation.filePath("mixxxbpmscheme.xml");
        oldFile = new QFile(oldFilePath);
        if (oldFile->exists()) {
            if (oldFile->copy(newFilePath))
                oldFile->remove();
            else {
                if (oldFile->error()==14) qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "The destination file already exists.";
                else qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "Error #" << oldFile->error();
            }
        }
        delete oldFile;
#ifdef __WINDOWS__
        oldFilePath = oldLocation.filePath("MixxxMIDIBindings.xml");
#else
        oldFilePath = oldLocation.filePath(".MixxxMIDIBindings.xml");
#endif
        newFilePath = newLocation.filePath("MixxxMIDIBindings.xml");
        oldFile = new QFile(oldFilePath);
        if (oldFile->exists()) {
            qWarning() << "The MIDI mapping file format has changed in this version of Mixxx. You will need to reconfigure your MIDI controller. See the Wiki for full details on the new format.";
            if (oldFile->copy(newFilePath))
                oldFile->remove();
            else {
                if (oldFile->error()==14) qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "The destination file already exists.";
                else qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "Error #" << oldFile->error();
            }
        }
        // Tidy up
        delete oldFile;
#ifdef __WINDOWS__
        QFile::remove(oldLocation.filePath("MixxxMIDIDevice.xml")); // Obsolete file, so just delete it
#else
        QFile::remove(oldLocation.filePath(".MixxxMIDIDevice.xml")); // Obsolete file, so just delete it
#endif

#ifdef __WINDOWS__
        oldFilePath = oldLocation.filePath("mixxx.cfg");
#else
        oldFilePath = oldLocation.filePath(".mixxx.cfg");
#endif
        newFilePath = newLocation.filePath(SETTINGS_FILE);
        oldFile = new QFile(oldFilePath);
        if (oldFile->copy(newFilePath))
            oldFile->remove();
        else {
                if (oldFile->error()==14) qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "The destination file already exists.";
//.........这里部分代码省略.........
开发者ID:badescunicu,项目名称:mixxx,代码行数:101,代码来源:upgrade.cpp


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