文本文件读写

QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QFile aFile(aFileName);
aFile.open(QIODevice::ReadOnly | QIODevice::Text)
aFile.readAll();
aFile.close();
二进制文件读写


QDataStream aStream(&aFile);
aStream.setVersion(QDataStream::Qt_5_9);
aStream.setByteOrder(QDataStream::LittleEndian);
qint16 rowCount,colCount;
aStream.readRawData((char *)&rowCount, sizeof(qint16));
aStream.readRawData((char *)&colCount, sizeof(qint16));
aStream.writeRawData((char *)&rowCount,sizeof(qint16));
char *buf;
uint strLen;
aStream.readBytes(buf,strLen);
QString str=QString::fromLocal8Bit(buf,strLen);
QString zhiLiang=aItem->data(Qt::DisplayRole).toString();
btArray=zhiLiang.toUtf8();
aStream.writeBytes(btArray,btArray.length());
文件目录操作

QString str=QCoreApplication::applicationDirPath();
QString str=QCoreApplication::applicationFilePath();
QString str=QCoreApplication::applicationName();
QStringList strList=QCoreApplication::libraryPaths();
QString curDir=QDir::currentPath();
QDir::tempPath();
QDir::rootPath();
QDir::homePath();
QDir::currentPath();
QDir::drives();
bool ok= dir.removeRecursively();
QString str=dir.absoluteFilePath(fileName);
QFileSystemWatcher fileWatcher;
fileWatcher.addPath(ui->editDir->text());
fileWatcher.removePath(ui->editDir->text());
QStringList strList=fileWatcher.files();
QStringList strList=fileWatcher.directories();
connect(&fileWatcher,&QFileSystemWatcher::fileChanged,
this,&Dialog::on_fileChanged);