文件、文件夹操作
- 路径下创建文件夹
#include <QDir>
QDir dir(Dir);
if(!dir.exists())
{
dir.mkdir(newDirName);
return;
}
- 读取txt文件
QString displayString;
QFile file("/home/alvin/text.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Can't open the file!"<<endl;
}
while(!file.atEnd())
{
QByteArray line = file.readLine();
QString str(line);
qDebug()<< str;
displayString.append(str);
}
字符串操作
QString QString::mid(int position, int n = -1) const
时间
- 计算当前系统时区
const int LOCAL_TIME_ZONE = 24 - QDateTime(QDate(1970,1,2), QTime(0,0,0), Qt::LocalTime).toTime_t() / 3600;