PDA

View Full Version : Problem with "setModified(bool)"



_SamSoft_
3rd June 2007, 10:23
Hy, I'm a french student (15 years old) so sorry for my english :p

Code 1)

connect(textEdit, SIGNAL(textChanged()), SLOT(documentWasModified()));

With this code, when I launch my application, my title is always "myfile* - myapp"

Code 2)

connect(textEdit->document(), SIGNAL(textChanged()), SLOT(documentWasModified()));

With the code 2), when I make a modification in my textEdit, the title stays "myfile - myapp" instead of "myfile* - myapp".

The code of "documentWasModified" :



void MainWindowimpl::documentWasModified()
{
setWindowModified(textEdit->document()->isModified());

QString name;
if (currentFile.isEmpty())
{
name = "sanstitre";
}
else
{
name = strippedName(currentFile);
}

setWindowTitle(tr("%1 - %2").arg(name).arg(tr("SamSoft_DEV")));
}


thank you in advance :)

marcel
3rd June 2007, 10:32
code 1) You must reset the title after saving, so it is your job to make the * disappear.

code 2) QTextDocument does not have a textChanged signal. Instead it provides the contentsChanged signal, but I'm guessing that using this won't make much difference over situation 1.

The bottom line is that when you save the file, you must manually remove the * from the window title.
For example, if you save with "CTRL+S", then in the slot connected to triggered() signal of this action, you parse the window title and remove the * from it, then you set it back.

Regards

_SamSoft_
3rd June 2007, 10:37
I'm going to try your solutions, thanks :)

_SamSoft_
3rd June 2007, 14:51
It's ok, my problem is resolved !

Thank you :D