本文整理汇总了C++中QDir::isRoot方法的典型用法代码示例。如果您正苦于以下问题:C++ QDir::isRoot方法的具体用法?C++ QDir::isRoot怎么用?C++ QDir::isRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDir
的用法示例。
在下文中一共展示了QDir::isRoot方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateGotoMenu
void QxFileBrowser::updateGotoMenu()
{
for (int i = 0, n = cwdPast_.count(); i < n; ++i) {
if (!QDir(cwdPast_.at(i)).exists()) {
cwdPast_.removeAt(i);
--i;
--n;
}
}
if (gotoMenu_) {
disconnect(gotoMenu_, 0, 0, 0);
gotoMenu_->setAttribute(Qt::WA_DeleteOnClose, true); // destruction workaround, HACK
gotoMenu_->close();
}
gotoMenu_ = new QMenu(this);
{
QFont font = gotoMenu_->font();
font.setPixelSize(styleManager()->constant("dirOpenMenuFontSizePx"));
gotoMenu_->setFont(font);
}
connect(gotoMenu_, SIGNAL(triggered(QAction*)), this, SLOT(cwdSet(QAction*)));
actionToPath_.clear();
QFileIconProvider iconProvider;
QDir dir = QDir::current();
while (!dir.isRoot()) {
dir.cdUp();
QAction* action = gotoMenu_->addAction(iconProvider.icon(QFileInfo(dir.path())), dir.isRoot() ? QDir::separator() : dir.dirName());
actionToPath_[action] = dir.path();
}
gotoMenu_->addSeparator();
recentMenu_ = gotoMenu_->addMenu(tr("Recent Places"));
{
QFont font = recentMenu_->font();
font.setPixelSize(styleManager()->constant("dirOpenMenuFontSizePx"));
recentMenu_->setFont(font);
}
// QxDesignHack::beautify(recentMenu_);
connect(recentMenu_, SIGNAL(triggered(QAction*)), this, SLOT(cwdSet(QAction*)));
int n = cwdPast_.count();
recentMenu_->setDisabled(n == 0);
for (int i = n-1; i >= 0; --i)
{
QString path = cwdPast_[i];
QString name = path; // QFileInfo(path).fileName();
if (name == QString()) name = QDir::separator();
QAction* action = recentMenu_->addAction(iconProvider.icon(QFileInfo(path)), name);
actionToPath_[action] = path;
}
gotoButton_->setMenu(gotoMenu_);
}
示例2: getFirstExistingDir
/* static */
QString QIFileDialog::getFirstExistingDir (const QString &aStartDir)
{
QString result = QString::null;
QDir dir (aStartDir);
while (!dir.exists() && !dir.isRoot())
{
QFileInfo dirInfo (dir.absolutePath());
if (dir == QDir(dirInfo.absolutePath()))
break;
dir = dirInfo.absolutePath();
}
if (dir.exists() && !dir.isRoot())
result = dir.absolutePath();
return result;
}
示例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: defaultDisplayName
QString BaseQtVersion::defaultDisplayName(const QString &versionString, const FileName &qmakePath,
bool fromPath)
{
QString location;
if (qmakePath.isEmpty()) {
location = QCoreApplication::translate("QtVersion", "<unknown>");
} else {
// Deduce a description from '/foo/qt-folder/[qtbase]/bin/qmake' -> '/foo/qt-folder'.
// '/usr' indicates System Qt 4.X on Linux.
QDir dir = qmakePath.toFileInfo().absoluteDir();
do {
const QString dirName = dir.dirName();
if (dirName == QLatin1String("usr")) { // System-installed Qt.
location = QCoreApplication::translate("QtVersion", "System");
break;
}
location = dirName;
// Also skip default checkouts named 'qt'. Parent dir might have descriptive name.
if (dirName.compare(QLatin1String("bin"), Qt::CaseInsensitive)
&& dirName.compare(QLatin1String("qtbase"), Qt::CaseInsensitive)
&& dirName.compare(QLatin1String("qt"), Qt::CaseInsensitive)) {
break;
}
} while (!dir.isRoot() && dir.cdUp());
}
return fromPath ?
QCoreApplication::translate("QtVersion", "Qt %1 in PATH (%2)").arg(versionString, location) :
QCoreApplication::translate("QtVersion", "Qt %1 (%2)").arg(versionString, location);
}
示例5: remount
/**
* @brief Remount the file path,the mount point will be found automatically.
* @param file the path of file.
* @param mountType "rw" or "ro"
*/
bool RootTools::remount(QString file, QString mountType)
{
if(mounts_.size() == 0){
mounts_ = getMounts();
}
bool foundMount = false;
int i = 0;
QDir dir = QFileInfo(file).dir();
while(!foundMount){
for(i = 0; i < mounts_.size(); i++){
if(dir.absolutePath() == mounts_[i][1]){
foundMount = true;
break;
}
}
dir.cdUp();
if(dir.isRoot())
break;
}
if(!foundMount)
return false;
QString cmd = "mount -o " + mountType + ",remount " + mounts_[i][0] + " " + mounts_[i][1] + "\n";
qDebug()<<"mount"<<cmd;
shell_.write(cmd.toStdString().c_str(), cmd.size());
shell_.waitForBytesWritten(100);
return true;
}
示例6: readConfig
void Configuration::readConfig()
{
if (!m_dirty)
return;
m_dirty = false;
QObject deleterParent;
QDir dir = QDir::current();
do {
QDir git = dir;
if (git.cd(".git")) {
m_repoDir = dir;
m_repoMetaDataDir = git;
QDir refs(git.absoluteFilePath("refs/heads"));
m_emptyRepo = refs.count() == 2; // only '.' and '..'
break;
}
if (!dir.cdUp())
break;
} while(!dir.isRoot());
QString home = QDir::homePath();
QFile *config;
config = new QFile(home + "/.vng/config", &deleterParent);
if (! config->exists())
config = new QFile(home + "/.darcs/defaults", &deleterParent);
if (config->exists()) {
if (! config->open(QIODevice::ReadOnly)) {
Logger::error() << "Failed to open config file, is it readable?\n";
return;
}
char buf[1024];
while(true) {
qint64 lineLength = config->readLine(buf, sizeof(buf));
if (lineLength == -1)
break;
QString line = QString::fromUtf8(buf, lineLength);
QString option;
if (line.startsWith("ALL "))
option = line.mid(3).trimmed();
else if (line.length() > m_section.length() && line.startsWith(m_section))
option = line.mid(m_section.length()).trimmed();
if (! option.isEmpty()) {
const int index = option.indexOf(' ');
if (index > 0) {
m_options.insert(option.left(index).trimmed(), option.mid(index).trimmed());
}
else
m_options.insert(option, QString());
}
}
config->close();
}
}
示例7: it
AddressBarButton::AddressBarButton(const QDir &newPath, AddressBar *parent, bool isAbsoluteRoot)
: QPushButton(parent)
, _path(newPath)
, _atLeastOneSubDir(false)
, _highlighted(false)
, _isAbsoluteRoot(isAbsoluteRoot)
, _addressBar(parent)
{
this->setFlat(true);
this->setMouseTracking(true);
QDir d = QDir(_path);
QDirIterator it(d.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot);
while (it.hasNext()) {
it.next();
if (it.fileInfo().isDir()) {
_atLeastOneSubDir = true;
break;
}
}
// Text + (space + arrow + space) if current dir has subdirectories
int width = fontMetrics().width(d.dirName());
if (_atLeastOneSubDir) {
// Special root folders like "/" or "D:\" on Windows are empty
if (d.isRoot()) {
/// XXX?
for (QFileInfo fileInfo : QDir::drives()) {
if (fileInfo.absolutePath() == _path.absolutePath()) {
break;
}
}
if (_isAbsoluteRoot) {
width += 10;
} else {
width += qMax(20, fontMetrics().width(AddressBar::getVolumeInfo(d.absolutePath())));
}
}
width += 28 + this->height() / 2;
this->setMinimumWidth(width);
} else {
this->setMinimumWidth(width + 18);
}
this->setText(d.dirName());
this->setMaximumWidth(width);
}
示例8: wrapInFunction
void wrapInFunction()
{
//! [0]
QDir("/home/user/Documents")
QDir("C:/Documents and Settings")
//! [0]
//! [1]
QDir("images/landscape.png")
//! [1]
//! [2]
QDir("Documents/Letters/Applications").dirName() // "Applications"
QDir().dirName() // "."
//! [2]
//! [3]
QDir directory("Documents/Letters");
QString path = directory.filePath("contents.txt");
QString absolutePath = directory.absoluteFilePath("contents.txt");
//! [3]
//! [4]
QDir dir("example");
if (!dir.exists())
qWarning("Cannot find the example directory");
//! [4]
//! [5]
QDir dir = QDir::root(); // "/"
if (!dir.cd("tmp")) { // "/tmp"
qWarning("Cannot find the \"/tmp\" directory");
} else {
QFile file(dir.filePath("ex1.txt")); // "/tmp/ex1.txt"
if (!file.open(QIODevice::ReadWrite))
qWarning("Cannot create the file %s", file.name());
}
//! [5]
//! [6]
QString bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin
QDir binDir(bin);
QString canonicalBin = binDir.canonicalPath();
// canonicalBin now equals "/usr/bin"
QString ls = "/local/bin/ls"; // where ls is the executable "ls"
QDir lsDir(ls);
QString canonicalLs = lsDir.canonicalPath();
// canonicalLS now equals "/usr/bin/ls".
//! [6]
//! [7]
QDir dir("/home/bob");
QString s;
s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg"
s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt"
//! [7]
//! [8]
QDir::setSearchPaths("icons", QStringList(QDir::homePath() + "/images"));
QDir::setSearchPaths("docs", QStringList(":/embeddedDocuments"));
...
QPixmap pixmap("icons:undo.png"); // will look for undo.png in QDir::homePath() + "/images"
QFile file("docs:design.odf"); // will look in the :/embeddedDocuments resource path
//! [8]
//! [9]
QDir dir("/tmp/root_link");
dir = dir.canonicalPath();
if (dir.isRoot())
qWarning("It is a root link");
//! [9]
//! [10]
// The current directory is "/usr/local"
QDir d1("/usr/local/bin");
QDir d2("bin");
if (d1 == d2)
qDebug("They're the same");
//! [10]
//! [11]
// The current directory is "/usr/local"
QDir d1("/usr/local/bin");
d1.setFilter(QDir::Executable);
QDir d2("bin");
if (d1 != d2)
//.........这里部分代码省略.........