class MyWord : public QMainWindow{.....}
void MyWord::fileOpen()
{
QString fileName = QFileDialog::getOpenFileName(this, QStringLiteral("打开"),QString(), QStringLiteral("HTML 文档 (*.htm *.html);;所有文件 (*.*)"));
if (!fileName.isEmpty()) {
QMdiSubWindow *existing = findMyChild(fileName);
if (existing) { // 若文档已打开,则直接激活
mdiArea->setActiveSubWindow(existing);
return;
}
MyChild *child = createMyChild();
if (child->loadFile(fileName)) {
statusBar()->showMessage(QStringLiteral("文件已载入"), 2000);
child->show();
enabledText(); //使得字体设置菜单可用
} else {
child->close();
}
}
}
QMdiSubWindow *MyWord::findMyChild(const QString &fileName)
{
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
f