本文整理汇总了C++中utils::FileReader类的典型用法代码示例。如果您正苦于以下问题:C++ FileReader类的具体用法?C++ FileReader怎么用?C++ FileReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileReader类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: populateModelFromMailCapFile
bool NickNameDialog::populateModelFromMailCapFile(const QString &fileName,
QStandardItemModel *model,
QString *errorMessage)
{
if (const int rowCount = model->rowCount())
model->removeRows(0, rowCount);
if (fileName.isEmpty())
return true;
Utils::FileReader reader;
if (!reader.fetch(fileName, QIODevice::Text, errorMessage))
return false;
// Split into lines and read
NickNameEntry entry;
const QStringList lines = QString::fromUtf8(reader.data()).trimmed().split(QLatin1Char('\n'));
const int count = lines.size();
for (int i = 0; i < count; i++) {
if (entry.parse(lines.at(i))) {
model->appendRow(entry.toModelRow());
} else {
qWarning("%s: Invalid mail cap entry at line %d: '%s'\n",
qPrintable(QDir::toNativeSeparators(fileName)),
i + 1, qPrintable(lines.at(i)));
}
}
model->sort(0);
return true;
}
开发者ID:Gardenya,项目名称:qtcreator,代码行数:27,代码来源:nicknamedialog.cpp
示例2: getSourceForUrl
static QByteArray getSourceForUrl(const QString &fileURl)
{
Utils::FileReader fileReader;
if (fileReader.fetch(fileURl))
return fileReader.data();
else
return Utils::FileReader::fetchQrc(fileURl);
}
开发者ID:C-sjia,项目名称:qt-creator,代码行数:9,代码来源:itemlibraryinfo.cpp
示例3: readFile
QByteArray QmlApp::readFile(const QString &filePath, bool &ok) const
{
Utils::FileReader reader;
if (!reader.fetch(filePath)) {
ok = false;
return QByteArray();
}
ok = true;
return reader.data();
}
开发者ID:aizaimenghuangu,项目名称:QtTestor,代码行数:12,代码来源:qmlapp.cpp
示例4: getSource
static QString getSource(const QString &fileName,
const CppModelManagerInterface::WorkingCopy &workingCopy)
{
if (workingCopy.contains(fileName)) {
return workingCopy.source(fileName);
} else {
Utils::FileReader reader;
if (!reader.fetch(fileName, QFile::Text)) // ### FIXME error reporting
return QString();
return QString::fromLocal8Bit(reader.data()); // ### FIXME encoding
}
}
开发者ID:pcacjr,项目名称:qt-creator,代码行数:13,代码来源:cppfindreferences.cpp
示例5: parseProject
void QmlProject::parseProject(RefreshOptions options)
{
Core::MessageManager *messageManager = Core::ICore::messageManager();
if (options & Files) {
if (options & ProjectFile)
delete m_projectItem.data();
if (!m_projectItem) {
Utils::FileReader reader;
if (reader.fetch(m_fileName)) {
QDeclarativeComponent *component = new QDeclarativeComponent(&m_engine, this);
component->setData(reader.data(), QUrl::fromLocalFile(m_fileName));
if (component->isReady()
&& qobject_cast<QmlProjectItem*>(component->create())) {
m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet<QString>,QSet<QString>)),
this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));
} else {
messageManager->printToOutputPane(tr("Error while loading project file %1.").arg(m_fileName));
messageManager->printToOutputPane(component->errorString(), true);
}
} else {
messageManager->printToOutputPane(tr("QML project: %1").arg(reader.errorString()), true);
}
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(projectDir().path());
m_modelManager->updateSourceFiles(m_projectItem.data()->files(), true);
QString mainFilePath = m_projectItem.data()->mainFile();
if (!mainFilePath.isEmpty()) {
mainFilePath = projectDir().absoluteFilePath(mainFilePath);
if (!QFileInfo(mainFilePath).isReadable()) {
messageManager->printToOutputPane(
tr("Warning while loading project file %1.").arg(m_fileName));
messageManager->printToOutputPane(
tr("File '%1' does not exist or is not readable.").arg(mainFilePath), true);
}
}
}
m_rootNode->refresh();
}
if (options & Configuration) {
// update configuration
}
if (options & Files)
emit fileListChanged();
}
开发者ID:mornelon,项目名称:QtCreator_compliments,代码行数:49,代码来源:qmlproject.cpp
示例6: parseProject
void QmlProject::parseProject(RefreshOptions options)
{
if (options & Files) {
if (options & ProjectFile)
delete m_projectItem.data();
if (!m_projectItem) {
QString errorMessage;
m_projectItem = QmlProjectFileFormat::parseProjectFile(m_fileName, &errorMessage);
if (m_projectItem) {
connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet<QString>,QSet<QString>)),
this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));
} else {
MessageManager::write(tr("Error while loading project file %1.")
.arg(m_fileName.toUserOutput()),
MessageManager::NoModeSwitch);
MessageManager::write(errorMessage);
}
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(projectDir().path());
if (modelManager())
modelManager()->updateSourceFiles(m_projectItem.data()->files(), true);
QString mainFilePath = m_projectItem.data()->mainFile();
if (!mainFilePath.isEmpty()) {
mainFilePath = projectDir().absoluteFilePath(mainFilePath);
Utils::FileReader reader;
QString errorMessage;
if (!reader.fetch(mainFilePath, &errorMessage)) {
MessageManager::write(tr("Warning while loading project file %1.")
.arg(m_fileName.toUserOutput()));
MessageManager::write(errorMessage);
} else {
m_defaultImport = detectImport(QString::fromUtf8(reader.data()));
}
}
}
m_rootNode->refresh();
}
if (options & Configuration) {
// update configuration
}
if (options & Files)
emit fileListChanged();
}
开发者ID:raphaelcotty,项目名称:qt-creator,代码行数:48,代码来源:qmlproject.cpp
示例7: loadFileContent
QByteArray FileConverter::loadFileContent(const QString &filePath, QString &errorMessage)
{
QByteArray ret;
Utils::FileReader fr;
QString absFilePath = filePath;
if (!filePath.startsWith(QLatin1String(":/"))) {
const QString srcProjectPath = convertedProjectContext().srcProjectPath();
absFilePath = srcProjectPath + QLatin1Char('/') + filePath;
}
fr.fetch(absFilePath);
if (!fr.errorString().isEmpty())
errorMessage = fr.errorString();
else
ret = fr.data();
return ret;
}
开发者ID:AltarBeastiful,项目名称:qt-creator,代码行数:16,代码来源:fileconverter.cpp
示例8: parseProject
void QmlProject::parseProject(RefreshOptions options)
{
if (options & Files) {
if (options & ProjectFile)
delete m_projectItem.data();
if (!m_projectItem) {
QString errorMessage;
m_projectItem = QmlProjectFileFormat::parseProjectFile(projectFilePath(), &errorMessage);
if (m_projectItem) {
connect(m_projectItem.data(), &QmlProjectItem::qmlFilesChanged,
this, &QmlProject::refreshFiles);
} else {
MessageManager::write(tr("Error while loading project file %1.")
.arg(projectFilePath().toUserOutput()),
MessageManager::NoModeSwitch);
MessageManager::write(errorMessage);
}
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(canonicalProjectDir().toString());
if (m_projectItem->targetDirectory().isEmpty())
m_projectItem->setTargetDirectory(canonicalProjectDir().toString());
if (auto modelManager = QmlJS::ModelManagerInterface::instance())
modelManager->updateSourceFiles(m_projectItem.data()->files(), true);
QString mainFilePath = m_projectItem.data()->mainFile();
if (!mainFilePath.isEmpty()) {
mainFilePath
= QDir(canonicalProjectDir().toString()).absoluteFilePath(mainFilePath);
Utils::FileReader reader;
QString errorMessage;
if (!reader.fetch(mainFilePath, &errorMessage)) {
MessageManager::write(tr("Warning while loading project file %1.")
.arg(projectFilePath().toUserOutput()));
MessageManager::write(errorMessage);
}
}
}
generateProjectTree();
}
if (options & Configuration) {
// update configuration
}
}
开发者ID:kai66673,项目名称:qt-creator,代码行数:47,代码来源:qmlproject.cpp
示例9: open
bool VcsBaseSubmitEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
if (fileName.isEmpty())
return false;
Utils::FileReader reader;
if (!reader.fetch(realFileName, QIODevice::Text, errorString))
return false;
const QString text = QString::fromLocal8Bit(reader.data());
if (!setFileContents(text.toUtf8()))
return false;
d->m_file->setFilePath(QFileInfo(fileName).absoluteFilePath());
d->m_file->setModified(fileName != realFileName);
return true;
}
开发者ID:ltcmelo,项目名称:qt-creator,代码行数:17,代码来源:vcsbasesubmiteditor.cpp
示例10: getParsedDocument
static Document::Ptr getParsedDocument(const QString &fileName,
CppTools::WorkingCopy &workingCopy,
Snapshot &snapshot)
{
QByteArray src;
if (workingCopy.contains(fileName)) {
src = workingCopy.source(fileName);
} else {
Utils::FileReader reader;
if (reader.fetch(fileName)) // ### FIXME error reporting
src = QString::fromLocal8Bit(reader.data()).toUtf8();
}
Document::Ptr doc = snapshot.preprocessedDocument(src, fileName);
doc->check();
snapshot.insert(doc);
return doc;
}
开发者ID:kai66673,项目名称:qt-creator,代码行数:18,代码来源:qtcreatorintegration.cpp
示例11: createUserFields
void VcsBaseSubmitEditor::createUserFields(const QString &fieldConfigFile)
{
Utils::FileReader reader;
if (!reader.fetch(fieldConfigFile, QIODevice::Text, Core::ICore::mainWindow()))
return;
// Parse into fields
const QStringList fields = fieldTexts(QString::fromUtf8(reader.data()));
if (fields.empty())
return;
// Create a completer on user names
const QStandardItemModel *nickNameModel = VcsPlugin::instance()->nickNameModel();
QCompleter *completer = new QCompleter(NickNameDialog::nickNameList(nickNameModel), this);
SubmitFieldWidget *fieldWidget = new SubmitFieldWidget;
connect(fieldWidget, SIGNAL(browseButtonClicked(int,QString)),
this, SLOT(slotSetFieldNickName(int)));
fieldWidget->setCompleter(completer);
fieldWidget->setAllowDuplicateFields(true);
fieldWidget->setHasBrowseButton(true);
fieldWidget->setFields(fields);
d->m_widget->addSubmitFieldWidget(fieldWidget);
}
开发者ID:ltcmelo,项目名称:qt-creator,代码行数:22,代码来源:vcsbasesubmiteditor.cpp
示例12: validator
MerDevicesXmlReader::MerDevicesXmlReader(const QString &fileName, QObject *parent)
: QObject(parent),
d(new MerDevicesXmlReaderPrivate)
{
Utils::FileReader reader;
d->error = !reader.fetch(fileName, QIODevice::ReadOnly);
if (d->error) {
d->errorString = reader.errorString();
return;
}
QXmlSchema schema;
schema.setMessageHandler(&d->messageHandler);
Utils::FileReader schemeReader;
d->error = !schemeReader.fetch(QString::fromLatin1("%1/mer/devices.xsd").arg(sharedDirPath()),
QIODevice::ReadOnly);
if (d->error) {
d->errorString = schemeReader.errorString();
return;
}
schema.load(schemeReader.data());
d->error = !schema.isValid();
if (d->error) {
d->errorString = d->messageHandler.errorString();
return;
}
QXmlSchemaValidator validator(schema);
validator.setMessageHandler(&d->messageHandler);
d->error = !validator.validate(reader.data());
if (d->error) {
d->errorString = d->messageHandler.errorString();
return;
}
d->query.setQuery(QString::fromLatin1("doc('%1')").arg(fileName));
d->query.setMessageHandler(&d->messageHandler);
d->error = !d->query.isValid();
if (d->error) {
d->errorString = d->messageHandler.errorString();
return;
}
d->error = !d->query.evaluateTo(d->receiver);
if (d->error)
d->errorString = d->messageHandler.errorString();
}
开发者ID:kaltsi,项目名称:sailfish-qtcreator,代码行数:48,代码来源:merdevicexmlparser.cpp
示例13: dump
void PluginDumper::dump(const Plugin &plugin)
{
if (plugin.hasPredumpedQmlTypesFile()) {
const Snapshot snapshot = m_modelManager->snapshot();
LibraryInfo libraryInfo = snapshot.libraryInfo(plugin.qmldirPath);
if (!libraryInfo.isValid())
return;
const QString &path = plugin.predumpedQmlTypesFilePath();
Utils::FileReader reader;
if (!reader.fetch(path, QFile::Text)) {
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::TypeInfoFileError, reader.errorString());
m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo);
return;
}
QString error;
QString warning;
const QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(reader.data(), &error, &warning);
if (error.isEmpty()) {
libraryInfo.setMetaObjects(objectsList);
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::TypeInfoFileDone);
} else {
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::TypeInfoFileError,
tr("Failed to parse '%1'.\nError: %2").arg(path, error));
}
if (!warning.isEmpty())
printParseWarnings(plugin.qmldirPath, warning);
m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo);
return;
}
ProjectExplorer::Project *activeProject = ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject();
if (!activeProject)
return;
ModelManagerInterface::ProjectInfo info = m_modelManager->projectInfo(activeProject);
if (info.qmlDumpPath.isEmpty()) {
const Snapshot snapshot = m_modelManager->snapshot();
LibraryInfo libraryInfo = snapshot.libraryInfo(plugin.qmldirPath);
if (!libraryInfo.isValid())
return;
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError,
tr("Could not locate the helper application for dumping type information from C++ plugins.\n"
"Please build the debugging helpers on the Qt version options page."));
m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo);
return;
}
QProcess *process = new QProcess(this);
process->setEnvironment(info.qmlDumpEnvironment.toStringList());
connect(process, SIGNAL(finished(int)), SLOT(qmlPluginTypeDumpDone(int)));
connect(process, SIGNAL(error(QProcess::ProcessError)), SLOT(qmlPluginTypeDumpError(QProcess::ProcessError)));
QStringList args;
if (plugin.importUri.isEmpty()) {
args << QLatin1String("--path");
args << plugin.importPath;
if (ComponentVersion(plugin.importVersion).isValid())
args << plugin.importVersion;
} else {
args << plugin.importUri;
args << plugin.importVersion;
args << plugin.importPath;
}
process->start(info.qmlDumpPath, args);
m_runningQmldumps.insert(process, plugin.qmldirPath);
}
开发者ID:renatofilho,项目名称:QtCreator,代码行数:71,代码来源:qmljsplugindumper.cpp
注:本文中的utils::FileReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论