textEdit->document()->setModified(false);
设置文档是否修改过,(这个一般用于关闭时提示保存)
setWindowModified(false);
就是窗口的标题上加个*号(在wps里就可以看到修改的文档会加个*)
经常作这个连接来动态显示
connect(textEdit->document(), SIGNAL(modificationChanged(bool)),
this, SLOT(setWindowModified(bool)));
void MainWindow :: setCurrentFile ( const QString & fileName )
{
static int sequenceNumber = 1;
//默认标题是否为空
isUntitled = fileName.isEmpty();
if(isUntitled)
{
curFile = tr("document%1.txt").arg(sequenceNumber++);
}
else
{
//返回fileName的标准路径
curFile = QFileInfo(fileName).canonicalFilePath();
}
//document()保存从文本解析的标题
//setModified()保存文档是否被修改过,默认false
textEdit->document()->setModified(false);
//被修改文档的窗口显示一个*号
setWindowModified(false);
setWindowFilePath(curFile);
}
这个属性只对windows有意义。它将文件路径与窗口关联。如果您设置了文件路径,但是没有设置窗口标题,
Qt将窗口标题设置为指定路径的文件名,使用QFileInfo::fileName()获得。
setWindowFilePath(curFile);