本文整理汇总了C++中QDir::dirName方法的典型用法代码示例。如果您正苦于以下问题:C++ QDir::dirName方法的具体用法?C++ QDir::dirName怎么用?C++ QDir::dirName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDir
的用法示例。
在下文中一共展示了QDir::dirName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createNewProject
/*
Create a new project.
- a new directory for the project
- an XML project file for the project, from template
- a stubbed out source file, from template
Make sure the path name doesn't have any spaces in it, so make can work happily.
Return the new project's name, or an empty string on failure.
*/
QString ProjectManager::createNewProject(const QString & newProjectPath)
{
QString projectPath = confirmValidProjectName(newProjectPath);
QDir newProjectDir;
newProjectDir.mkpath(projectPath);
newProjectDir.setPath(projectPath);
QString newProjName = newProjectDir.dirName();
// grab the templates for a new project
QString templatePath = "resources/templates";
#ifdef MCBUILDER_TEST_SUITE
templatePath.prepend("../");
#endif
QDir templatesDir(MainWindow::appDirectory().filePath(templatePath));
// create the project file from our template
QFile templateFile(templatesDir.filePath("project_template.xml"));
templateFile.copy(newProjectDir.filePath(newProjName + ".xml"));
templateFile.close();
templateFile.setFileName(templatesDir.filePath("makefile_template.txt"));
templateFile.copy(newProjectDir.filePath("Makefile"));
templateFile.close();
templateFile.setFileName(templatesDir.filePath("config_template.txt"));
templateFile.copy(newProjectDir.filePath("config.h"));
templateFile.close();
templateFile.setFileName(templatesDir.filePath("source_template.txt"));
if (templateFile.open(QIODevice::ReadOnly | QFile::Text)) {
// and create the main file
QFile mainFile(newProjectDir.filePath(newProjName + ".c"));
if (mainFile.open(QIODevice::WriteOnly | QFile::Text)) {
QTextStream out(&mainFile);
out << QString("// %1.c").arg(newProjName) << endl;
out << QString("// created %1").arg(QDate::currentDate().toString("MMM d, yyyy") ) << endl;
out << templateFile.readAll();
mainFile.close();
}
QFileInfo fi(mainFile);
addToProjectFile(newProjectDir.path(), fi.filePath());
templateFile.close();
}
return newProjectDir.path();
}
示例2: subdir
QList<br::FilesWithLabel> br::getFilesWithLabels(QDir dir)
{
dir = QDir(dir.canonicalPath());
QStringList files;
foreach (const QString &file, dir.entryList(QDir::Files))
files.append(dir.absoluteFilePath(file));
QList<br::FilesWithLabel> filesWithLabels;
filesWithLabels.append(br::FilesWithLabel(dir.dirName(),files));
foreach (const QString &folder, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
QDir subdir(dir);
bool success = subdir.cd(folder); if (!success) qFatal("cd failure.");
filesWithLabels.append(getFilesWithLabels(subdir));
}
return filesWithLabels;
}
示例3: isPercentMultiple
bool PSPApplication::isPercentMultiple(QDir dir)
{
//Get the dir name of the pbp container
QString dirName = dir.dirName();//dir.absolutePath();
//Set the name of the other dir
QString otherName = dirName;
if (dirName.endsWith("%"))
{
otherName.resize(otherName.length() - 1);
}
else
{
otherName.append("%");
}
//Now we have to check that both the otherName dir exists
//and it has a valid PBP file
dir.cdUp();
QDir otherDir(dir.absolutePath() +"/"+ otherName);
if (!otherDir.exists())
{
return false;
}
//Find the eboot.pbp file inside the dir
QFileInfoList files;
files = otherDir.entryInfoList(QDir::Files | QDir::NoSymLinks);
for (int i = 0; i < files.size(); ++i)
{
if (files.at(i).fileName().toLower() == "eboot.pbp")
{
if (isPBPSignature(files.at(i).filePath()))
{
return true; //We have the correct directory and contains a correct pbp file
}
}
}
return false;
}
示例4: s
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QUrl DREAM3DHelpUrlGenerator::generateHTMLUrl(QString htmlName)
{
QString appPath = qApp->applicationDirPath();
QDir helpDir = QDir(appPath);
QString s("file://");
#if defined(Q_OS_WIN)
s = s + "/"; // Need the third slash on windows because file paths start with a drive letter
#elif defined(Q_OS_MAC)
if (helpDir.dirName() == "MacOS")
{
helpDir.cdUp();
helpDir.cdUp();
helpDir.cdUp();
}
#else
// We are on Linux - I think
QFileInfo fi( helpDir.absolutePath() + Detail::Dream3DHelpPath + htmlName + ".html");
if (fi.exists() == false)
{
// The help file does not exist at the default location because we are probably running from the build tree.
// Try up one more directory
helpDir.cdUp();
}
#endif
#if defined(Q_OS_WIN)
QFileInfo fi( helpDir.absolutePath() + Detail::Dream3DHelpPath + htmlName + ".html");
if (fi.exists() == false)
{
// The help file does not exist at the default location because we are probably running from visual studio.
// Try up one more directory
helpDir.cdUp();
}
#endif
s = s + helpDir.absolutePath() + Detail::Dream3DHelpPath + htmlName + ".html";
return QUrl(s);
}
示例5: StoreTestimonials
/************************************************************
* WriteToFile
* -----------------------------------------------------------
* - Overloaded
* - see WriteToFile(Qstring)
* Returns true only if it successfully writes
* Returns false if it fails to open, write or if there are
* no customers in the list.
* ------------------------------------------------------------
* File path is set when first establishing the database
*************************************************************/
bool MainProgramWindow::StoreTestimonials()
{
QDir dataPath = QDir::current();
bool writeStatus;
// Failstate signal
writeStatus = false;
// Initialize QFile and write failed, Appended File to path, QFile Creates
while(dataPath.dirName() != "Class-Project")
{
dataPath.cdUp();
}
dataPath.cd("Database-Files");
QFile testimonialDataFile((dataPath.path() + "/Testimonials.txt"));
if(testimonialDataFile.open((QIODevice::ReadWrite | QIODevice::Text)|QIODevice::Truncate))
{
QTextStream out(&testimonialDataFile);
out << bWindow->getTestimonials();
// Flushes output buffer
out.flush();
writeStatus = true;
} // END OPEN FILE IF
// Flushes and coses the data file
testimonialDataFile.flush();
testimonialDataFile.close();
// Returns True or False status
return writeStatus;
}// **** END METHOD **** //
示例6: processLine
void DumpRenderTree::processLine(const QString &input)
{
QString line = input;
m_expectedHash = QString();
if (m_dumpPixels) {
// single quote marks the pixel dump hash
int i = line.indexOf('\'');
if (i > -1) {
m_expectedHash = line.mid(i + 1, line.length());
line.remove(i, line.length());
}
}
if (line.startsWith(QLatin1String("http:"))
|| line.startsWith(QLatin1String("https:"))
|| line.startsWith(QLatin1String("file:"))) {
open(QUrl(line));
} else {
QFileInfo fi(line);
if (!fi.exists()) {
QDir currentDir = QDir::currentPath();
// Try to be smart about where the test is located
if (currentDir.dirName() == QLatin1String("LayoutTests"))
fi = QFileInfo(currentDir, line.replace(QRegExp(".*?LayoutTests/(.*)"), "\\1"));
else if (!line.contains(QLatin1String("LayoutTests")))
fi = QFileInfo(currentDir, line.prepend(QLatin1String("LayoutTests/")));
if (!fi.exists()) {
emit ready();
return;
}
}
open(QUrl::fromLocalFile(fi.absoluteFilePath()));
}
fflush(stdout);
}
示例7: defined
QDir
Tools::pluginsPath(void)
{
QDir dir = QCoreApplication::applicationDirPath();
#if defined(Q_OS_MAC)
if (dir.dirName() == "MacOS") {
dir.cdUp();
}
dir.cd("plugins");
dir.cd("lugdulov");
#elif defined(Q_OS_WIN32)
dir.cd("plugins");
dir.cd("lugdulov");
#else
dir.cdUp();
dir.cd("lib");
dir.cd("lugdulov");
dir.cd("plugins");
#endif
return dir;
}
示例8: QDir
Global::Global()
{
appDirPath = QCoreApplication::applicationDirPath();
QDir appDir = QDir(appDirPath);
#if defined(Q_OS_MAC)
if (appDir.dirName() == "MacOS") {
//We're in the mac package and need to get back to the package to access relative directories
appDir.cdUp();
appDir.cdUp();
appDir.cdUp(); //Root dir where app is located
appDirPath = appDir.absolutePath();
}
#endif
pebbleDataPath = appDirPath + "/PebbleData/";
file = new QFile(pebbleDataPath+"pebblelog.txt");
bool res = file->open(QIODevice::Unbuffered | QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text);
pLogfile = NULL;
if (res) {
pLogfile = new QDebug(file);
*pLogfile << "Pebble log file\n";
}
revision = new char[80];
//See PebbleQt.pro for DEFINES statement that creates PEBBLE_VERSION
sprintf(revision,"Build %s on %s using QT:%s",PEBBLE_VERSION, PEBBLE_DATE, PEBBLE_QT);
//qDebug(revision);
sdr = NULL;
perform.InitPerformance();
beep.setSource(QUrl::fromLocalFile(pebbleDataPath + "beep-07.wav"));
beep.setLoopCount(1);
beep.setVolume(0.25f);
primaryScreen = QGuiApplication::primaryScreen();
}
示例9: setContentFile
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void HelpDialog::setContentFile(QUrl sourceLocation)
{
QDir aPluginDir = QDir(dream3dApp->applicationDirPath());
QString aPluginDirStr = aPluginDir.absolutePath();
QString thePath;
#if defined(Q_OS_WIN)
if (aPluginDir.cd("Help") )
{
thePath = aPluginDir.absolutePath();
}
else if (aPluginDir.cd("../Help") )
{
thePath = aPluginDir.absolutePath();
}
#elif defined(Q_OS_MAC)
if (aPluginDir.dirName() == "MacOS")
{
aPluginDir.cdUp();
aPluginDir.cdUp();
aPluginDir.cdUp();
}
// aPluginDir.cd("Plugins");
thePath = aPluginDir.absolutePath() + "/Help";
#else
if (aPluginDir.cd("Help"))
{
thePath = aPluginDir.absolutePath();
}
#endif
thePath = QString("file:///").append(thePath).append("/").append(sourceLocation.toString());
// qDebug() << "Help File Path:" << thePath() << "\n";
helpBrowser->setSource(QUrl(thePath));
// Set the Home Page File
m_HomeUrl = QUrl(thePath);
this->show();
}
示例10: requestDownloadFile
void Camera::requestDownloadFile(const CameraFileRef& file, const QDir& destinationFolderPath, const std::function<void(EdsError error, QString outputFilePath)>& callback) {
// check if destination exists and create if not
if ( !destinationFolderPath.exists() ) {
bool status = destinationFolderPath.mkpath(".");
if (!status) {
std::cerr << "ERROR - failed to create destination folder path '" << destinationFolderPath.dirName().toStdString() << "'" << std::endl;
return callback(EDS_ERR_INTERNAL_ERROR, NULL);
}
}
QString filePath = destinationFolderPath.filePath(QString::fromStdString(file->getName()));
EdsStreamRef stream = NULL;
EdsError error = EdsCreateFileStream(filePath.toStdString().c_str(), kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
if (error != EDS_ERR_OK) {
std::cerr << "ERROR - failed to create file stream" << std::endl;
goto download_cleanup;
}
error = EdsDownload(file->mDirectoryItem, file->getSize(), stream);
if (error != EDS_ERR_OK) {
std::cerr << "ERROR - failed to download" << std::endl;
goto download_cleanup;
}
error = EdsDownloadComplete(file->mDirectoryItem);
if (error != EDS_ERR_OK) {
std::cerr << "ERROR - failed to mark download as complete" << std::endl;
goto download_cleanup;
}
download_cleanup:
if (stream) {
EdsRelease(stream);
}
callback(error, filePath);
}
示例11: createNewProject
/*
Create a new project.
- a new directory for the project
- an XML project file for the project, from template
- a stubbed out source file, from template
Make sure the path name doesn't have any spaces in it, so make can work happily.
Return the new project's name, or an empty string on failure.
*/
QString ProjectManager::createNewProject(QString newProjectPath)
{
confirmValidProjectName(&newProjectPath);
if(newProjectPath.contains(" ")) // if there are still spaces in the path, we have problems
return "";
QDir newProjectDir;
newProjectDir.mkpath(newProjectPath);
newProjectDir.setPath(newProjectPath);
QString newProjName = newProjectDir.dirName();
// grab the templates for a new project
QDir templatesDir = QDir::current().filePath("resources/templates");
// create the project file from our template
QFile templateFile(templatesDir.filePath("project_template.xml"));
templateFile.copy(newProjectDir.filePath(newProjName + ".xml"));
templateFile.close();
templateFile.setFileName(templatesDir.filePath("source_template.txt"));
if( templateFile.open(QIODevice::ReadOnly | QFile::Text) )
{
// and create the main file
QFile mainFile(newProjectDir.filePath(newProjName + ".c"));
if( mainFile.open(QIODevice::WriteOnly | QFile::Text) )
{
QTextStream out(&mainFile);
out << QString("// %1.c").arg(newProjName) << endl;
out << QString("// created %1").arg(QDate::currentDate().toString("MMM d, yyyy") ) << endl;
out << templateFile.readAll();
mainFile.close();
}
QFileInfo fi(mainFile);
addToProjectFile(newProjectDir.path(), fi.filePath(), "thumb");
templateFile.close();
}
return newProjectDir.path();
}
示例12: RemoveDirectory
bool RemoveDirectory(QDir &aDir)
{
qDebug() << "Now Deleting " << aDir;
QDirIterator iterator(aDir.absolutePath (), QDirIterator::NoIteratorFlags);
while(iterator.hasNext ())
{
iterator.next ();
qDebug() << "Iterating over - " << iterator.filePath ();
if(iterator.fileInfo ().isFile ())
{
qDebug () << "Deleting File";
QFile::remove (iterator.filePath ());
}
if (iterator.fileInfo ().isDir () && iterator.fileName () != "." && iterator.fileName () != "..")
{
QDir rDel(iterator.filePath ());
RemoveDirectory(rDel);
}
}
// Delete the root director
QString dirName = aDir.dirName ();
aDir.cdUp ();
aDir.rmdir (dirName);
}
示例13: idx
AddressBarButton::AddressBarButton(const QString &newPath, int index, QWidget *parent) :
QPushButton(parent), _path(QDir::toNativeSeparators(newPath)), idx(index), _atLeastOneSubDir(true)
{
if (_path.right(1) != QDir::separator()) {
_path += QDir::separator();
}
this->setFlat(true);
this->setMouseTracking(true);
QDir d = QDir(_path);
/*foreach (QFileInfo fileInfo, d.entryInfoList(QStringList(), QDir::NoDotAndDotDot)) {
qDebug() << fileInfo.absoluteFilePath();
if (fileInfo.isDir()) {
_atLeastOneSubDir = true;
//break;
}
}*/
// padding + text + (space + arrow + space) if current dir has subdirectories
int width = fontMetrics().width(d.dirName());
if (_atLeastOneSubDir) {
width += 30;
}
this->setMinimumWidth(width);
this->setMaximumWidth(width);
}
示例14: name
QString Maildir::name() const
{
const QDir dir(d->path);
return dir.dirName();
}
示例15: updateUniformVariableValuesFromDialog
void UniformValue::updateUniformVariableValuesFromDialog(int rowIdx, int colIdx, QVariant newValue)
{
switch (type) {
case INT:
ivalue = newValue.toInt();
break;
case FLOAT:
fvalue = newValue.toDouble();
break;
case BOOL:
bvalue = newValue.toBool() != 0;
break;
case VEC2:
case VEC3:
case VEC4:
vec4[colIdx] = newValue.toDouble();
break;
case IVEC2:
case IVEC3:
case IVEC4:
ivec4[colIdx] = newValue.toInt();
break;
case BVEC2:
case BVEC3:
case BVEC4:
bvec4[colIdx] = newValue.toBool() != 0;
break;
case MAT2:
mat2[rowIdx][colIdx] = newValue.toDouble();
break;
case MAT3:
mat3[rowIdx][colIdx] = newValue.toDouble();
break;
case MAT4:
mat4[rowIdx][colIdx] = newValue.toDouble();
break;
case SAMPLER1D:
case SAMPLER2D:
case SAMPLER3D:
case SAMPLERCUBE:
case SAMPLER1DSHADOW:
case SAMPLER2DSHADOW: {
QString newPath;
// * choose the filename with a dialog (55 by convention)
if (rowIdx == 5 && colIdx == 5) {
QFileDialog fd(0, "Choose new texture");
QDir texturesDir = QDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
if (texturesDir.dirName() == "debug" ||
texturesDir.dirName() == "release")
texturesDir.cdUp();
#elif defined(Q_OS_MAC)
if (texturesDir.dirName() == "MacOS") {
for (int i = 0; i < 4; ++i) {
texturesDir.cdUp();
if (texturesDir.exists("textures"))
break;
}
}
#endif
texturesDir.cd("textures");
fd.setDirectory(texturesDir);
fd.move(500, 100);
if (fd.exec()) {
QStringList sels = fd.selectedFiles();
newPath = sels[0];
}
} else
newPath = newValue.toString();
// Load the new texture from given file
if(textureLoaded)
glDeleteTextures(1, &textureId);
QImage img, imgScaled, imgGL;
QFileInfo finfo(newPath);
if(!finfo.exists()) {
qDebug() << "Texture" << name << "in"
<< newPath << ": file do not exists";
} else if (!img.load(newPath)) {
QMessageBox::critical(0, "Meshlab",
newPath + ": Unsupported texture format");
}
glEnable(GL_TEXTURE_2D);
// image has to be scaled to a 2^n size. We choose the first 2^N <= picture size.
int bestW = pow(2.0, floor(::log(double(img.width())) / ::log(2.0)));
int bestH = pow(2.0, floor(::log(double(img.height())) / ::log(2.0)));
//.........这里部分代码省略.........