本文整理汇总了C++中QDir::mkpath方法的典型用法代码示例。如果您正苦于以下问题:C++ QDir::mkpath方法的具体用法?C++ QDir::mkpath怎么用?C++ QDir::mkpath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDir
的用法示例。
在下文中一共展示了QDir::mkpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getDataPath
QString BtsSpawnClient::getDataPath()
{
if(!p->dataPath.isEmpty())
return p->dataPath;
QDir dataPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
dataPath.mkpath("sync_storage");
if(!dataPath.cd("sync_storage"))
{
qWarning("Failed creating sync storage dir!");
return QString();
}
p->dataPath = dataPath.absolutePath();
return p->dataPath;
}
示例2: setGlobalConfigPath
bool BrisaConfigurationManager::setGlobalConfigPath(QString &path)
{
if (instance) {
qWarning() << "BrisaConfigurationManager was already instanciated. "
"Call setConfigFilePath to change the already existing instance configuration file path.";
}
QDir dir;
if (dir.exists(path)) {
globalConfigPath = path;
return true;
} else if (dir.mkpath(path)) {
qWarning() << "Path " << path << " does not exist. Creating path...";
globalConfigPath = path;
return true;
}
checkConfigFile = false;
return false;
}
示例3: createXmlFile
// need to refactor this out
// we probably want the process instead of this function
// cmakeproject then could even run the cmake process in the background, adding the files afterwards
// sounds like a plan
void CMakeManager::createXmlFile(Utils::QtcProcess *proc, const QString &arguments,
const QString &sourceDirectory, const QDir &buildDirectory,
const Utils::Environment &env, const QString &generator)
{
QString buildDirectoryPath = buildDirectory.absolutePath();
buildDirectory.mkpath(buildDirectoryPath);
proc->setWorkingDirectory(buildDirectoryPath);
proc->setEnvironment(env);
const QString srcdir = buildDirectory.exists(QLatin1String("CMakeCache.txt")) ?
QString(QLatin1Char('.')) : sourceDirectory;
QString args;
Utils::QtcProcess::addArg(&args, srcdir);
Utils::QtcProcess::addArgs(&args, arguments);
Utils::QtcProcess::addArg(&args, generator);
proc->setCommand(cmakeExecutable(), args);
proc->start();
}
示例4: saveResources
void FlashcardsDeck::saveResources (QString deckFileName, bool verbose)
{
if (resourceAbsoluteToDeckPathMap.empty()) return;
verify (!(mediaDirectoryName.isEmpty() || mediaDirectoryName.isNull()), "Media directory not specified or empty.");
QDir createMediaIn = QFileInfo (deckFileName).dir();
verify (createMediaIn.exists(), "Failed to access parent directory of '" + deckFileName + "'.");
verify (createMediaIn.mkpath (mediaDirectoryName), "Failed to create media subdirectory '" + mediaDirectoryName + "' for deck file '" + deckFileName +"'.");
for (std::pair <QString, QString> absoluteToRelative : resourceAbsoluteToDeckPathMap.toStdMap())
{
QString destination = createMediaIn.absolutePath() + "/" + mediaDirectoryName + "/" + absoluteToRelative.second;
QFileInfo sourceFile (absoluteToRelative.first), destinationFile (destination);
if (destinationFile.exists() && sourceFile.lastModified() == destinationFile.lastModified() && sourceFile.size() == destinationFile.size())
{
if (verbose)
qstderr << "File '" << absoluteToRelative.first << "' has same last accessed time as '" << destination << "': skipping." << endl;
continue;
}
//bool copied = QFile::copy (absoluteToRelative.first, destination);
// Copy preserving timestamps via 'cp'
bool copied = false;
#ifdef Q_OS_LINUX
QProcess process;
process.start ("cp", QStringList() << sourceFile.absoluteFilePath() << destinationFile.absoluteFilePath() << "--preserve=timestamps");
verify (process.waitForFinished(), "Failed to wait for 'cp' to finish.");
copied = process.exitCode() == 0;
#else
#error This platform is not supported. Add more cases or test if the existing code works.
#endif
verify (copied, "Failed to copy '" + absoluteToRelative.first + "' to '" + destination + "'.");
if (verbose)
qstderr << "Copied resource '" + absoluteToRelative.first + "' to '" + destination + "'." << endl;
}
if (verbose)
qstderr << resourceAbsoluteToDeckPathMap.size() << " resources saved." << endl;
}
示例5: getIniFile
QString getIniFile( const QString& s )
{
#if defined Q_OS_MAC
return QString( "%1/../%2.ini" ).arg( QApplication::applicationDirPath() ).arg( s );
#elif defined Q_OS_WIN
/* We used to store the ini file in the application directory, before moving to the
correct location, but some users like it better the old way... so if we find a .ini
file in the application directory, we're using it */
QString oldinifile = QString( "%1/%2.ini" ).arg( QApplication::applicationDirPath() ).arg( s );
if ( QFile::exists( oldinifile )) return oldinifile;
return QString( "%1/%2.ini" ).arg( getDataDirPath() ).arg(s);
#else
/*
We used to store the ini file in ~/.$SOMETHING/$SOMETHING.ini, were $SOMETHING could
be at least yabause or yabause-qt
With release 0.9.12 we moved to the XDG compliant location ~/.config/yabause/qt/yabause.ini
and we don't want this location to depends on the program name anymore.
This code is trying to copy the content from the old location to the new.
In the future, we may drop support for the old location and rewrite the following to:
return QString( "%1/.config/yabause/qt/yabause.ini" ).arg( QDir::homePath() );
*/
QString xdginifile = QString( "%1/.config/yabause/qt/yabause.ini" ).arg( QDir::homePath() );
QString oldinifile = QString( "%1/.%2/%2.ini" ).arg( QDir::homePath() ).arg( s );
if ( not QFile::exists( xdginifile ) )
{
QString xdgpath = QString( "%1/.config/yabause/qt" ).arg( QDir::homePath() );
if ( ! QFile::exists( xdgpath ) )
{
// for some reason, Qt doesn't provide a static mkpath method O_o
QDir dir;
dir.mkpath( xdgpath );
}
if ( QFile::exists( oldinifile ) )
QFile::copy( oldinifile, xdginifile );
}
return xdginifile;
#endif
}
示例6: cpWallpaper
void Launcher_page::cpWallpaper(QString extWallpaperPath)
{
/* 用bash脚本拷贝壁纸
QStringList strList;
QString command = Global::mingw64 + "\\bash.exe";
strList << "test.sh" << Global::mingw64 << Global::srcPath << extWallpaperPath << "2";
qDebug() << command;
// strList << Global::mingw64 << Global::prj_home_path + "\\bin\\bash_helper.sh"<< Global::srcPath << extWallpaperPath << "2";
qDebug() << strList;
p->start("bash", strList);
*/
QDir *extDir = new QDir(extWallpaperPath);
QStringList fileList = extDir->entryList();
QString pathWallpaperOverlay = Global::srcPath + "/" + Global::overlayPath + "/packages/apps/Launcher3/res/drawable-nodpi";
QString wallpaperXml = Global::srcPath + "/packages/apps/Launcher3/res/values/wallpapers.xml";
QDir *overlayDir = new QDir(pathWallpaperOverlay);
if(fileList.length() > 2)
{
if(!overlayDir->mkpath(pathWallpaperOverlay))
{
qDebug() << "mkpath fail.. " << pathWallpaperOverlay;
QMessageBox::critical(this, tr("错误警告 : "), tr("创建目录") + pathWallpaperOverlay + tr("失败,请检查目标路径是否有可写权限,或目标路径被文件浏览器打开"));
return;
}
for(int i = 2; i < fileList.length(); i++)
{
QStringList nameList = fileList[i].split(".");
QImage srcImg(extWallpaperPath + "/" + fileList[i]);
qDebug() << extWallpaperPath + "/" + fileList[i];
QImage smlImg = srcImg.scaled(200,200);
if(!smlImg.save(pathWallpaperOverlay + "/" + nameList[0] + "_small." + nameList[1]))
{
qDebug() << "small image save fail";
}
QFile::copy(extWallpaperPath + "/" + fileList[i], pathWallpaperOverlay +"/" + fileList[i]);
qDebug() << pathWallpaperOverlay + "/" + nameList[0] + "_small." + nameList[1];
textHelper.addWallpaperXml(wallpaperXml, nameList[0]);
}
}else
{
QMessageBox::information(this, tr("提示~~~"), tr("壁纸文件夹内空。。。。。"));
}
}
示例7: test_query
/*!
* \brief Database::Database
* \param databaseDir directory to load/store the database
* \param schemaDirectory directory of the SQL schema for the database
* \param parent
*/
Database::Database(const QString &databaseDir, const QString &schemaDirectory,
QObject* parent) :
QObject(parent),
m_databaseDirectory(databaseDir),
m_sqlSchemaDirectory(schemaDirectory),
m_db(new QSqlDatabase())
{
if (!QFile::exists(m_databaseDirectory)) {
QDir dir;
bool createOk = dir.mkpath(m_databaseDirectory);
if (!createOk)
qWarning() << "Unable to create DB directory" << m_databaseDirectory;
}
m_albumTable = new AlbumTable(this, this);
m_mediaTable = new MediaTable(this, this);
// Open the database.
if (!openDB())
restoreFromBackup();
// Attempt a query to make sure the DB is valid.
QSqlQuery test_query(*m_db);
if (!test_query.exec("SELECT * FROM SQLITE_MASTER LIMIT 1")) {
logSqlError(test_query);
restoreFromBackup();
}
QSqlQuery query(*m_db);
// Turn synchronous off.
if (!query.exec("PRAGMA synchronous = OFF")) {
logSqlError(query);
return;
}
// Enable foreign keys.
if (!query.exec("PRAGMA foreign_keys = ON")) {
logSqlError(query);
return;
}
// Update if needed.
upgradeSchema(schemaVersion());
}
示例8: initTestCase
void tst_QMimeDatabase::initTestCase()
{
QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString()));
QStandardPaths::setTestModeEnabled(true);
m_localMimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/mime";
if (QDir(m_localMimeDir).exists()) {
QVERIFY2(QDir(m_localMimeDir).removeRecursively(), qPrintable(m_localMimeDir + ": " + qt_error_string()));
}
QString errorMessage;
#ifdef USE_XDG_DATA_DIRS
// Create a temporary "global" XDG data dir for later use
// It will initially contain a copy of freedesktop.org.xml
QVERIFY2(m_temporaryDir.isValid(),
("Could not create temporary subdir: " + m_temporaryDir.errorString()).toUtf8());
const QDir here = QDir(m_temporaryDir.path());
m_globalXdgDir = m_temporaryDir.path() + QStringLiteral("/global");
const QString globalPackageDir = m_globalXdgDir + QStringLiteral("/mime/packages");
QVERIFY(here.mkpath(globalPackageDir));
qputenv("XDG_DATA_DIRS", QFile::encodeName(m_globalXdgDir));
qDebug() << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir;
const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml");
const QString xmlFileName = QLatin1String(RESOURCE_PREFIX) + freeDesktopXml;
const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml;
QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage));
#endif
m_testSuite = QFINDTESTDATA("testfiles");
if (m_testSuite.isEmpty())
qWarning("%s", qPrintable(testSuiteWarning()));
errorMessage = QString::fromLatin1("Cannot find '%1'");
for (uint i = 0; i < sizeof additionalMimeFiles / sizeof additionalMimeFiles[0] - 1; i++) {
const QString resourceFilePath = QString::fromLatin1(RESOURCE_PREFIX) + QLatin1String(additionalMimeFiles[i]);
QVERIFY2(QFile::exists(resourceFilePath), qPrintable(errorMessage.arg(resourceFilePath)));
m_additionalMimeFileNames.append(QLatin1String(additionalMimeFiles[i]));
m_additionalMimeFilePaths.append(resourceFilePath);
}
initTestCaseInternal();
m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE");
}
示例9: loadData
void HighScoresModel::loadData()
{
QDir gluonDir = QDir::home();
gluonDir.mkpath( ".gluon/" + QString( serviceURI ) );
gluonDir.cd( ".gluon/" + QString( serviceURI ) );
QString filename = gluonDir.absoluteFilePath( "highscores.gdl" );
QFile dataFile( filename );
while( 1 )
{
if( !dataFile.open( QIODevice::ReadOnly ) )
{
if( !QFile::exists( filename ) )
{
qDebug() << "Cannot find the file " << filename << ", creating new";
dataFile.close();
saveData(); //Create a blank file if it doesn't exist
continue; //Try to open again
}
else
{
qDebug() << "Cannot open the file " << filename;
return; //return from loadData()
}
}
else
{
break; //File opened successfully
}
}
QTextStream highScoresReader( &dataFile );
QString fileContents = highScoresReader.readAll();
dataFile.close();
if( fileContents.isEmpty() )
{
qDebug() << "Something is wrong with the high scores file";
return;
}
QList<GluonObject*> highScores = GluonCore::GDLHandler::instance()->parseGDL( fileContents, 0 );
rootNode = highScores.at( 0 );
}
示例10: receiveFile
void FileReceiver::receiveFile(void) {
QDir dir = QFileInfo(filePath).dir();
if(!dir.exists())
dir.mkpath(dir.absolutePath());
file = new QFile(filePath);
if(file->open(QIODevice::WriteOnly)) {
buffer = new char[bufferSize];
active = true;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
timer->start(timeout);
} else {
socket->close();
emit progressUpdated(FM_Receive, FO_Error, type, &id, &peerId, &filePath);
}
}
示例11: playerMoved
void MainWindow::playerMoved(int player, const Tile * tile, const MoveHistoryEntry & move)
{
emit updateNeeded();
boardUi->playerMoved(player, tile, move);
if (move.move.tileMove.isNull())
emit gameEvent(tr("A non-suitable tile was drawn and discarded."));
else
emit gameEvent(tr("Player %1 moved.").arg(player+1));
// QSettings settings;
// settings.beginGroup("games");
// int size = settings.beginReadArray("game");
// settings.endArray(); //game
// settings.beginWriteArray("game");
// settings.setArrayIndex(size-1);
// int moveSize = settings.beginReadArray("moves");
// settings.endArray(); //moves
// auto const & history = game->getMoveHistory();
// settings.beginWriteArray("moves");
// for (size_t i = moveSize; i < history.size(); ++i)
// {
// settings.setArrayIndex((int)i);
// MoveHistoryEntry const & m = history[i];
// settings.setValue("tile", m.tile);
// settings.setValue("x", m.move.tileMove.x);
// settings.setValue("y", m.move.tileMove.y);
// settings.setValue("orientation", m.move.tileMove.orientation);
// settings.setValue("meeple", m.move.meepleMove.nodeIndex);
// }
// settings.endArray(); //moves
// settings.endArray(); //game
// settings.endGroup(); //games
QString const & dataLoc = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QDir dir = QDir(dataLoc).absoluteFilePath("games");
if (dir.mkpath(".") && gameStartTimestamp != -1)
game->storeToFile(dir.absoluteFilePath(QString::number(gameStartTimestamp)));
}
示例12: switchLanguage
void XCA_application::switchLanguage(QAction* a)
{
QLocale lang = a->data().toLocale();
setupLanguage(lang);
QString dir = getUserSettingsDir();
QFile file(dir +QDir::separator() +"defaultlang");
if (lang == QLocale::system()) {
file.remove();
return;
}
QDir d;
d.mkpath(dir);
if (file.open(QIODevice::WriteOnly)) {
file.write(lang.name().toUtf8());
}
}
示例13: QObject
Cache::Cache(QObject *parent) :
QObject(parent)
{
m_cacheonly = false;
QDesktopServices dirs;
m_path = dirs.storageLocation(QDesktopServices::CacheLocation);
m_path += "/nelisquare/";
//qDebug() << "Cache location: " << m_path;
if (m_path.length()) {
QDir dir;
if (!dir.mkpath(m_path))
qDebug () << "Error creating cache directory";
}
manager = new QNetworkAccessManager (this);
connect(manager,SIGNAL(finished(QNetworkReply*)),SLOT(onDownloadFinished(QNetworkReply*)));
}
示例14: fileOpen
void TextEdit::fileOpen(const QString &curFile) {
QDir dir;
fileName = curFile;
if(!QFile::exists(path + fileName)||fileName.isEmpty())
{
QString newFile("");
do
{
newFile = "page_" + QTime::currentTime().toString("mmsszzz") + ".html";
}
while (QFile::exists(path + newFile));
fileName = newFile;
}
name = fileName;
name.replace(".html","");
QString imagesPath = path + name;
dir.mkpath(imagesPath);
load(path + fileName);
}
示例15: init
int Database::init ()
{
_db = QSqlDatabase::database("quote");
if (! _db.isOpen())
{
QString s = QDir::homePath() + "/QtTrader/db/";
QDir dir;
if (! dir.mkpath(s))
{
qDebug() << "Database::init: error creating database" << s;
return 0;
}
s.append("quote");
_db = QSqlDatabase::addDatabase("QSQLITE", "quote");
_db.setHostName("QtTrader");
_db.setDatabaseName(s);
_db.setUserName("QtTrader");
_db.setPassword("QtTrader");
if (! _db.open())
{
qDebug() << "Database::init:" << _db.lastError().text();
return 0;
}
}
QSqlQuery q(_db);
QString s = "CREATE TABLE IF NOT EXISTS symbolIndex (";
s.append("a INTEGER PRIMARY KEY"); // auto increment index
s.append(", name TEXT"); // entity name
s.append(", key TEXT"); // attribute
s.append(", value TEXT"); // value
s.append(")");
q.exec(s);
if (q.lastError().isValid())
{
qDebug() << "Database::init:" << _db.lastError().text();
return 0;
}
return 1;
}