本文整理汇总了C++中QFileInfo::dir方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::dir方法的具体用法?C++ QFileInfo::dir怎么用?C++ QFileInfo::dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::dir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLayersFolderPath
QString RotoCanvas::getLayersFolderPath(QFileInfo frameFI, int frameNumber, bool createEnable)
{
//such as <sequenceName>/frames/<frameNumber>/layers
QString seqName=RotoCanvas::getSeqName(frameFI);
//qInfo() << "seqName:" << seqName; //see also qInfo,qDebug,qWarning,qCritical,qFatal
QString seqPath=frameFI.dir().filePath(seqName);
QDir seqDir(seqPath);
if (createEnable) {
if (!seqDir.exists()) frameFI.dir().mkdir(seqName);
}
QString framesPath=seqDir.filePath("frames");
//qInfo()<<"framesPath:"<<framesPath;
QDir framesDir(framesPath);
if (createEnable) {
if (!framesDir.exists()) seqDir.mkdir("frames");
}
QString thisFramePath=framesDir.filePath(QString::number(frameNumber));
//qInfo()<<"thisFramePath:"<<thisFramePath;
QDir thisFrameDir=QDir(thisFramePath);
if (createEnable) {
if (!thisFrameDir.exists()) framesDir.mkdir(QString::number(frameNumber));
}
QString layersPath=QDir(thisFramePath).filePath("layers");
//qInfo()<<"layersPath:"<<layersPath;
QDir layersDir=QDir(layersPath);
if (createEnable) {
if (!layersDir.exists()) thisFrameDir.mkdir("layers");
}
return layersPath;
}
示例2: CouldSync
SyncConfLevel Plugin::CouldSync (const QString& path)
{
QFileInfo fi (path);
if (!fi.isDir () || !fi.isWritable ())
return SyncConfLevel::None;
if (fi.dir ().entryList (QDir::Dirs).contains (".rockbox", Qt::CaseInsensitive) ||
fi.dir ().entryList (QDir::Dirs).contains ("music", Qt::CaseInsensitive))
return SyncConfLevel::High;
return SyncConfLevel::Medium;
}
示例3: detectBaseName
QString AddToArchive::detectBaseName(const QStringList &paths) const
{
QFileInfo fileInfo = QFileInfo(paths.first());
QDir parentDir = fileInfo.dir();
QString base = parentDir.absolutePath() + QLatin1Char('/');
if (paths.size() > 1) {
if (!parentDir.isRoot()) {
// Use directory name for the new archive.
base += parentDir.dirName();
}
} else {
// Strip filename of its extension, but only if present (see #362690).
if (!QMimeDatabase().mimeTypeForFile(fileInfo.fileName(), QMimeDatabase::MatchExtension).isDefault()) {
base += fileInfo.completeBaseName();
} else {
base += fileInfo.fileName();
}
}
// Special case for compressed tar archives.
if (base.right(4).toUpper() == QLatin1String(".TAR")) {
base.chop(4);
}
if (base.endsWith(QLatin1Char('/'))) {
base.chop(1);
}
return base;
}
示例4: validateDBLocate
bool ConfigForm::validateDBLocate()
{
QFileInfo theFile;
QDir theDir;
QString warningStr = "";
ui->LineEditDBLocate->setText( ui->LineEditDBLocate->text().trimmed() );
theFile = QFileInfo(ui->LineEditDBLocate->text());
theDir = theFile.dir();
if ( !theDir.exists() )
{
warningStr += tr("The directory selected for create DB index not exists !\n");
}
if ( theFile.fileName().isEmpty() )
{
warningStr += tr("The file name selected for create DB index is empty !\n");
}
if ( !theDir.exists() || theFile.fileName().isEmpty() )
{
warningStr += tr("Invalide input:") + QString(" \"") + ui->LineEditDBLocate->text() + QString("\"\n\n") + tr("Operation is aborded !") ;
QMessageBox::warning( this, tr("Invalide Input"), warningStr );
ui->LineEditDBLocate->selectAll();
return FALSE;
}
else
{
return TRUE;
}
}
示例5: getTargetFiles
//------------------------------------------------------------------------------
void MainWindow::getTargetFiles(QListWidget *listWidget, QLineEdit *labelFileStatus, QStringList files)
{
for (int ii = 0; ii < files.count(); ii++) {
QFileInfo *fileinfo = new QFileInfo(files[ii]);
if(fileinfo->isFile()){
if(! getTargetFile(listWidget, files[ii], files.count() - ii - 1)){
break;
}
inputFilesPath = fileinfo->dir().absolutePath();
}
else{
QMessageBox::StandardButton reply;
reply = QMessageBox::information(this, tr("Confirm"),
tr("Select all files in the folder?") + "\n\n" + files[ii],
QMessageBox::Yes | QMessageBox::No | QMessageBox::Abort);
if (reply == QMessageBox::Yes){
if(! getTargetFolder(listWidget, files[ii])){
break;
}
inputFilesPath = files[ii];
}
else if(reply == QMessageBox::No){
continue;
}
else{
break;
}
}
}
rewriteFileStatus(listWidget, labelFileStatus);
}
示例6: exportModels
// Export all currently loaded models in the referenced format
void Aten::exportModels()
{
Messenger::enter("Aten::exportModels");
QFileInfo fileInfo;
QString newFilename;
// Loop over loaded models
for (Model* m = models_.first(); m != NULL; m = m->next)
{
// Set current model
setCurrentModel(m);
// Generate new filename for model, with new suffix
fileInfo.setFile(m->filename());
newFilename = fileInfo.dir().absoluteFilePath(fileInfo.baseName() + "." + exportModelPlugin_->extensions().first());
QFileInfo newFileInfo(newFilename);
// Make sure that the new filename is not the same as the old filename
if (fileInfo == newFileInfo)
{
Messenger::print("Exported file would overwrite the original (%s) - not converted.", qPrintable(m->filename()));
continue;
}
if (exportModel(m, newFilename, exportModelPlugin_, FilePluginStandardImportOptions(), exportModelPluginOptions_)) Messenger::print("Model '%s' saved to file '%s' (%s)", qPrintable(m->name()), qPrintable(newFilename), qPrintable(exportModelPlugin_->name()));
else Messenger::print("Failed to save model '%s'.", qPrintable(m->name()));
m->enableUndoRedo();
}
Messenger::exit("Aten::exportModels");
}
示例7: download
bool ExportCommon::download(ExportContext *ctx, QString url, QString to) {
QString filePath = QDir::cleanPath(ctx->outputDir.absoluteFilePath(to));
QFileInfo fi = QFileInfo(filePath);
ctx->outputDir.mkpath(fi.dir().absolutePath());
QFile file(filePath);
if (file.exists())
return true;
if (file.open(QIODevice::WriteOnly)) {
exportInfo("Downloading %s\n", url.toStdString().c_str());
QUrl imageUrl(url);
FileDownloader *m_pImgCtrl = new FileDownloader(imageUrl);
QEventLoop loop;
loop.connect(m_pImgCtrl, SIGNAL(downloaded()), &loop, SLOT(quit()));
loop.exec();
QByteArray data = m_pImgCtrl->downloadedData();
delete m_pImgCtrl;
if (data.length() > 0) {
file.write(data);
return true;
} else
exportError("Failed to download %s\n", url.toStdString().c_str());
} else
exportError("Can't open file %s\n", to.toStdString().c_str());
return false;
}
示例8: copyFile
bool JasonQt_File::copyFile(const QFileInfo &sourcePath, const QFileInfo &targetPath, const bool &cover)
{
if(sourcePath.filePath()[sourcePath.filePath().size() - 1] == '/')
{
return false;
}
if(targetPath.filePath()[targetPath.filePath().size() - 1] == '/')
{
return false;
}
if(!targetPath.dir().isReadable())
{
if(!QDir().mkpath(targetPath.path()))
{
return false;
}
}
if(targetPath.isFile() && !cover)
{
return true;
}
return QFile::copy(sourcePath.filePath(), targetPath.filePath());
}
示例9: writeFile
bool JasonQt_File::writeFile(const QFileInfo &targetFilePath, const QByteArray &data, const bool &cover)
{
if(!targetFilePath.dir().isReadable())
{
if(!QDir().mkpath(targetFilePath.path()))
{
return false;
}
}
if(targetFilePath.isFile() && !cover)
{
return true;
}
QFile file(targetFilePath.filePath());
if(!file.open(QIODevice::WriteOnly))
{
return false;
}
file.write(data);
file.waitForBytesWritten(10000);
return true;
}
示例10: LOG
bool W3cXmlPlugin::process(const QString *infoListfile)
{
LOG("BEGIN W3cXmlPlugin::process infoListfile=" << infoListfile);
if (infoListfile == NULL && m_dir.exists()) {
LOG("W3cXmlPlugin::process search for config.xml");
// Search for config.xml file
QFileInfoList tempExtract = m_dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
LOG("W3cXmlPlugin::process got entryInfoList");
foreach (const QFileInfo &isWidgetDir, tempExtract ) {
if (!isWidgetDir.fileName().compare("config.xml", Qt::CaseSensitive)) {
// We found the config.xml
QString filePath = isWidgetDir.absoluteFilePath();
if (!filePath.isEmpty()) {
QFileInfo f = filePath;
m_dir = f.dir();
LOG("W3cXmlPlugin::process found config.xml at " << filePath);
m_parser->setFile(filePath);
if (m_parser->parseFile()) {
setAttributeMap();
LOG("END W3cXmlPlugin::process xml parsing successful");
return true;
}
}
}
} // end of foreach
}
示例11: on_cmdRun_clicked
void MainWindow::on_cmdRun_clicked()
{
if (selectedFile != "")
{
VideoCapture vid(selectedFile.toStdString().c_str());
VideoWriter vout;
vout.open((selectedFile + "out.mpeg").toStdString().c_str(),CV_FOURCC('M','P','E','G'),30,Size(vid.get(CV_CAP_PROP_FRAME_WIDTH), vid.get(CV_CAP_PROP_FRAME_HEIGHT)));
qDebug() << "Frame cnt " << frame_count;
QFileInfo filedir = QFileInfo(selectedFile);
QDir currdir = filedir.dir();
int sample_size = frame_count;
if (sample_size <= 0)
return;
int sample_interval = frame_count / sample_size;
int sample_cnt = 0;
ui->prog->setMaximum(frame_count);
bool undistorted = ui->chkDistort->isChecked();
Mat cammatrix;
Mat distortion;
double rms;
if (undistorted)
{
FileStorage file(calibFile.toStdString().c_str(),FileStorage::READ);
file["rms"] >> rms;
file["cameramatrix"] >> cammatrix;
file["distortion"] >> distortion;
}
for (int i = 0; i < frame_count; i++)
{
Mat r;
vid >> r;
QString writepath = selectedFile + "-" + QString::number(i) + ".png";
Mat c;
if (undistorted)
{
undistort(r, c, cammatrix, distortion);
}
else
{
c = r;
}
imwrite(writepath.toStdString().c_str(), c);
vout << c;
ui->prog->setValue(i);
}
ui->prog->setValue(frame_count);
}
示例12: file
QString CertTableModel::Item::loadFromTemplateFile(const QFileInfo & entry) {//QString::isEmpty -> ok
//file example: /CN=Konstantine Kozachuk/[email protected]/UID=123
_templateFile = entry.filePath();
_dir = entry.dir();
_baseName = entry.baseName();
QFile file(_templateFile);
if(!file.open(QFile::ReadOnly))
return file.errorString();
const QByteArray arr = file.readAll();
const QString str = arr;
auto lines = str.split('\n', QString::SkipEmptyParts);
if(lines.count()!=1)
return tr("Invalid file format: more than 1 non-empty line in %1")
.arg(QDir::toNativeSeparators(_templateFile));
const QString line = lines[0];
_templateLine.append(line.toUtf8());
auto parts = line.split('/', QString::SkipEmptyParts);
bool formatOk = parts.size() == 2 || parts.size() == 3;
if(!formatOk)
return tr("Invalid format of file %1: %2 parts, looking for 2 or 3")
.arg(QDir::toNativeSeparators(_templateFile))
.arg(parts.size());
for(QString part: parts) {
if(!part.contains('='))
return tr("Invalid format: must be key=value in %1")
.arg(QDir::toNativeSeparators(_templateFile));
auto kv = part.split('=', QString::SkipEmptyParts);
if(kv.size() != 2)
return tr("Invalid format: must be key=value in %1")
.arg(QDir::toNativeSeparators(_templateFile));
const QString key = kv.first();
const QString value = kv.last();
if(key == "CN") {
_name = value;
} else if(key == "emailAddress") {
_mail = value;
} else if(key == "UID") {
_InfoCardId = value;
} else {
return tr("Unknown key %1 in %2").arg(key)
.arg(QDir::toNativeSeparators(_templateFile));
}
}
_name = _name.trimmed();
_mail = _mail.trimmed();
if(_name.isEmpty())
return tr("Invalid format: empty name in %1")
.arg(QDir::toNativeSeparators(_templateFile));
if(_mail.isEmpty())
return tr("Invalid format: empty email in %1")
.arg(QDir::toNativeSeparators(_templateFile));
_certPair = pathByExt("p12");
QFileInfo cert(_certPair);
if(cert.exists()) {
_certCreated = cert.lastModified();
}
return QString();
}
示例13: foreach
//Pack every subdirectory
foreach (QFileInfo sourceDirectory, directories) {
if (sourceDirectory.dir().count() == 0) continue; //ignore empty folders
qint64 startByte = file.size();
if (!this->Pack_Directory(file, sourceDirectory.filePath())) return false;
//Update the table entry with the new pointers
if (!this->Write_Buffer_To_File(file, this->Get_Byte_Array_From_qint64(startByte), directoryTable.value(sourceDirectory.fileName()))) return false;
}
示例14: QfsIsWritable
/*---------------------------------------------------------------------------*/
bool QfsIsWritable (QFileInfo Qi) /* no file => check if dir is writable */
{
if ( Qi .exists()) return Qi.isWritable();
else if (!Qi.dir().exists()) return false;
else {
QFileInfo Qd(Qi.path()); return Qd.isWritable();
//+
// fprintf(stderr, "Dir(%s)%s[%x]\n", Qd.fileName().cStr(),
//- Qd.isWritable() ? "writable" : "read-only", (int)Qd.permissions());
} }
示例15: open
bool KmzHandler::open( const QString &kmz )
{
QuaZip zip( kmz );
if ( !zip.open( QuaZip::mdUnzip ) ) {
mDebug() << "Failed to extract " << kmz;
return false;
}
QTemporaryFile outputDir ( QDir::tempPath() + "/marble-kmz-XXXXXX" );
outputDir.setAutoRemove( false );
outputDir.open();
if ( !QFile::remove( outputDir.fileName() ) || !QDir("/").mkdir( outputDir.fileName() ) ) {
mDebug() << "Failed to create temporary storage for extracting " << kmz;
return false;
}
m_kmzPath = outputDir.fileName();
QuaZipFile zipFile( &zip );
for ( bool moreFiles=zip.goToFirstFile(); moreFiles; moreFiles=zip.goToNextFile() ) {
QFileInfo output = QFileInfo( outputDir.fileName() + "/" + zip.getCurrentFileName() );
if ( !output.dir().exists() ) {
QDir::root().mkpath( output.dir().absolutePath() );
}
QFile outputFile( output.absoluteFilePath() );
outputFile.open( QIODevice::WriteOnly );
zipFile.open( QIODevice::ReadOnly );
outputFile.write( zipFile.readAll() );
outputFile.close();
zipFile.close();
m_kmzFiles << output.absoluteFilePath();
if ( output.suffix().toLower() == "kml" ) {
if ( !m_kmlFile.isEmpty() ) {
mDebug() << "File" << kmz << "contains more than one .kml files";
}
m_kmlFile = output.absoluteFilePath();
}
}
zip.close();
return true;
}