PDA

View Full Version : Saving a QtFile



deeee
26th May 2010, 04:48
Hi

I have a problem with the name of the file when saving it. when I open a new file , its name is untitled.txt and when I modify it the * appears but if I save the file normally there should be only the file name ( without * ) which is not the case and I don't understand where is the problem
here is the function and at the end the title of my window.


thanks



void MainWindow::setCurrentFile(const QString &fileName)
{
curFile = fileName;
setWindowFilePath(curFile);

QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
files.removeAll(fileName);
files.prepend(fileName);
while (files.size() > MaxRecentFiles)
files.removeLast();
settings.setValue("recentFileList", files);

foreach (QWidget *widget, QApplication::topLevelWidgets()) {
MainWindow *mainWin = qobject_cast<MainWindow *>(widget);
if (mainWin)
mainWin->updateRecentFileActions();
}
QString shownName;
if (curFile.isEmpty())
shownName = "untitled.txt";
else
shownName = strippedName(curFile);

setWindowTitle(tr("%1 - %2").arg(shownName).arg(tr("my application name")));
}

aamer4yu
26th May 2010, 06:09
setWindowTitle(tr("%1 - %2").arg(shownName).arg(tr("my application name")));
you are explicitly showing the asterik '*' ,,,, arent you ??

Lykurg
26th May 2010, 08:20
you are explicitly showing the asterik '*' ,,,, arent you ??

No, the syntax is right. But I don't see that you are using QWidget::setWindowModified() anywhere. That the * works, you have to tell if something have changed. So in your load function you have to call
setWindowModified(false);

deeee
26th May 2010, 18:09
ok, thanks, so what do I have to do exactly to make it work ?

deeee
27th May 2010, 00:51
Thanks so much for your answer. In fact I had to add this line


setWindowModified(false);

in the functions save() and saveAs(). and now it works perfectly