Window Title not showing name of file [Solved]
-
wrote on 12 Sept 2011, 16:56 last edited by
I seem to be having an issue with the title not being updated to the name of the file, here's the code, I've gotten, I've matched it up with the example online, but still doesn't appear on the title bar.
bool TextEditor::save() {} codes below;
[code]
bool TextEditor::save()
{
if (curFile.isEmpty()){
return saveAs();
} else {
return saveFile(curFile);
}
}[/code]
bool TextEditor::saveAs() { } codes below;
[code]
bool TextEditor::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this);
if (fileName.isEmpty())
return false;return saveFile(fileName);
}
[/code]bool TextEditor::saveFIle(const QString &fileName) {} codes below;
[code]
bool TextEditor::saveFile(const QString &fileName)
{QFile file(fileName); if (!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(this, tr("Error"), tr("Error, cannot write file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QTextStream out(&file); QApplication::setOverrideCursor(Qt::WaitCursor); out << textEdit->toPlainText(); QApplication::restoreOverrideCursor(); setCurrentFile(fileName); statusBar()->showMessage(tr("File saved."), 2000); return true;
}
[/code]void TextEditor::setCurrentFile(const QString &fileName) { } codes below;
[code]
void TextEditor::setCurrentFile(const QString &fileName)
{
curFile = fileName;QString shownName = curFile; if (curFile.isEmpty()) shownName = "Untitled.txt"; setWindowFilePath(fileName);
}
[/code]Can anybody see what I did wrong? =/.
-
wrote on 12 Sept 2011, 17:14 last edited by
perhaps you should use
@
setWindowFilePath(fileName);
@instead of
@
setWindowFilePath(shownName);
@Did you set a custom window title?
-
wrote on 12 Sept 2011, 17:22 last edited by
[quote author="Gerolf" date="1315847645"]perhaps you should use
@
setWindowFilePath(fileName);
@instead of
@
setWindowFilePath(shownName);
@Did you set a custom window title?[/quote]
Oooooooooooh, maybe that's my problem there, thanks, checking as I'm writing this response. It iddn 't work, I did have it as setWindowFilePath(fileName); changed it to setWindowFilePath(shownName); same results, not giving file name in the title.
And yes, I did
I did:
[code]
setWindowTitle(tr("Text Editor -- Edit Text Files & Sources"));
[/code]IF that is what you're referring to?
-
wrote on 12 Sept 2011, 17:31 last edited by
Oh, and here's an error message I'm getting, I'm running KDE, so it's something X Related I Think:
[code]
kfilemodule(5856) KSambaSharePrivate::findSmbConf: KSambaShare: Could not find smb.conf!
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 20 (X_GetProperty)
Resource id: 0x6400aaf
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 20 (X_GetProperty)
Resource id: 0x6406b4a[/code]
when I click the save Menu Item.
-
wrote on 13 Sept 2011, 06:25 last edited by
The docs of "QWidget::setWindowFilePath() ":http://doc.qt.nokia.com/4.7/qwidget.html#windowFilePath-prop states it clearly:
bq. If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.
-
wrote on 13 Sept 2011, 18:36 last edited by
[quote author="Volker" date="1315895143"]The docs of "QWidget::setWindowFilePath() ":http://doc.qt.nokia.com/4.7/qwidget.html#windowFilePath-prop states it clearly:
bq. If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.
[/quote]THanks, another thing I noticed, setWindowFilePath only makes sense in Windows, I have to use QFileInfo.
-
wrote on 14 Sept 2011, 04:53 last edited by
Thanks for the replies, it was due to a custom window title, I took that out, and put
[code]
Editor.setApplicationName("Text Editor");
[/code]Text Editor doesn't space in the Title Bar, can't figure out a workaround, but it's okay, now it's working, =).. And put Solved after the subject line, =). Am not sure how I would have reffered to my custom window title in codes, using it, but that's okay too.
1/7