QT  - 讨论区

标题:Qt Tutorial 009:使用QDir操作文件目录

2014年02月25日 星期二 09:28

QDir提供了针对文件目录的一系列API,包括获取当前路径,创建文件夹,遍历文件夹中的元素等等。

The QDir class provides access to directory structures and their contents.

A QDir is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. It can also be used to access Qt's resource system.

Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.

A QDir can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.

编程示例如下:

#include <QCoreApplication>
#include <QDir>
#include <QString>
#include <QDebug>
#include <QStringList>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    auto dir=QDir::current();
    qDebug() << dir.absolutePath();
    auto list=dir.entryList();
    for(auto file : list){
        qDebug() << file ;
    }
    dir.mkdir("testdir");
    dir.cd("testdir");
    dir.mkdir("testdir2");
    dir.cdUp();
    list=dir.entryList();
    for(auto file : list){
        qDebug() << file;
    }
    dir.rmdir("testdir/testdir2");
    dir.rmdir("testdir");
    return a.exec();
}

参考资料:

http://qt-project.org/doc/qt-5/qdir.html

2014年02月27日 星期四 14:19

qt现在主要用在哪些方面,目前诺基亚已经托管QT了,
塞班系统也不行了,想了解QT的发展现状和应用范围。

2014年02月27日 星期四 16:41

根据我的研究,Qt目前广泛用于跨平台的桌面软件,比如著名的BitCoin官方客户端就是使用Qt编写的。Qt编写的桌面软件在界面观感和执行效率方面让Java相形见绌。

从Qt的官方宣传来看,Qt目前已经可以作为移动终端(包括Android和iOS)的开发环境,这也会是一个发展方向,类似的解决方案可以参考MonoTouch。

从C++程序开发角度来看,Qt是一个丰富多彩包罗万象的C++ Library(Qt不仅仅是一个GUI库),使用Qt可以大大提高C++应用程序的开发效率。

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号