我有一个程序可以多次打开同一个文件.
如果此文件当前是打开的,我想在打开任何文件之前检查,因为我不想多次打开同一个文件.
是否有内置函数可以检查文件当前是否打开或任何其他方式可以做到这一点?
代码:
QString openFilePath = QFileDialog::getOpenFileName(this->mainWindow, "Open File");
if(openFilePath == ""){
return;
}
QFile openFile(openFilePath);
if(!openFile.open(QFile::ReadWrite)){
QMessageBox::critical(this->mainWindow, "Can't Open file", "Can't access to the file.");
}
QTextStream fileContent(&openFile);
QFileInfo fileInfo(openFile);
this->createEmptyFile(fileInfo.fileName());
this->txtEditor->setText(fileContent.readAll());
Run Code Online (Sandbox Code Playgroud)
在我看来,你的问题实际上与编程意义上的文件打开无关,而是与你的应用程序逻辑完全相关.您需要在内部保留所有当前打开的文件的列表(在您的GUI显示此类文件的意义上),并检查用户是否打开新文件.
| 归档时间: |
|
| 查看次数: |
1026 次 |
| 最近记录: |