depth
This article mainly analyzes the Windows platform, and Mac and Linux are not involved for the time being
This article only analyzes the Win32 API/Windows Com component/STL library function level, and does not explore the lower-level code
This article QT version 5.15.2
class diagram
QTemporaryFile inherits QFile
QFile、QSaveFile继承QFileDevice
QFileDevice inherits QIODevice
QIODevice, QFileSystemWatcher inherit QObject
QLockFile, QFileInfo, QDir, QFileSelector have no inheritance relationship
There is a QObjectData pointer d_ptr in QObject. d_ptr is a protected member variable, which means that each subclass can modify d_ptr content. In QObject d_ptr points to QObjectPrivate,
d_ptr in QIODevice points to QIODevicePrivate
d_ptr in QFileDevice points to QFileDevicePrivate
d_ptr in QFile points to QFilePrivate
d_ptr-oriented QTemporaryFilePrivate in QTemporaryFile
QFileInfo, QDir, and QLockFile do not inherit QObject, so there is no pointer d_ptr pointing to QObjectData. But each also declares that the d_ptr variable points to its own private class
d_ptr in QFileInfo points to QFileInfoPrivate
d_ptr in QDir points to QDirPrivate
d_ptr in QLockFile points to QLockFilePrivate
Inspiration:
This Private class writing method is suitable for scenarios where the exported interface is stable, the internal implementation details are not disclosed, and the internals can be modified flexibly
It can be used in usage scenarios such as paid plug-ins and software reverse engineering
QFileSelector
effect
Realize automatic selection of different configuration files in different environments.
Example of use
#include <QFileSelector>
#include <QFile>
int main(int argc, char* argv[])
{
QFileSelector tmp;
QString filePath = tmp.select("D:/hx1.txt");
QFile file(filePath);
if (file.open(QIODevice::ReadOnly))
{
auto arrData = file.readAll();
}
return 0;
}
Main function call process and principle
QFileSelector::select
write to the end
For now, I will write this first. No matter what opinions or suggestions you have, you can write them in the comment area and discuss them together.