September 12, 2011

RichardM198030 RichardM1980..
Lab Rat
95 posts

Window Title not showing name of file [Solved]

 

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;

  1. bool TextEditor::save()
  2. {
  3.     if (curFile.isEmpty()){
  4.         return saveAs();
  5.     } else {
  6.         return saveFile(curFile);
  7.     }
  8. }

bool TextEditor::saveAs() { } codes below;

  1. bool TextEditor::saveAs()
  2. {
  3.    QString fileName = QFileDialog::getSaveFileName(this);
  4.    if (fileName.isEmpty())
  5.        return false;
  6.  
  7.    return saveFile(fileName);
  8. }

bool TextEditor::saveFIle(const QString &fileName) {} codes below;

  1. bool TextEditor::saveFile(const QString &fileName)
  2. {
  3.  
  4.     QFile file(fileName);
  5.     if (!file.open(QFile::WriteOnly | QFile::Text)) {
  6.         QMessageBox::warning(this, tr("Error"), tr("Error, cannot write file %1:\n%2.")
  7.                .arg(fileName)
  8.                .arg(file.errorString()));
  9.         return false;
  10.     }
  11.  
  12.     QTextStream out(&file);
  13.     QApplication::setOverrideCursor(Qt::WaitCursor);
  14.     out << textEdit->toPlainText();
  15.     QApplication::restoreOverrideCursor();
  16.  
  17.  
  18.     setCurrentFile(fileName);
  19.     statusBar()->showMessage(tr("File saved."), 2000);
  20.  
  21.  
  22.     return true;
  23. }

void TextEditor::setCurrentFile(const QString &fileName) { } codes below;

  1. void TextEditor::setCurrentFile(const QString &fileName)
  2. {
  3.     curFile = fileName;
  4.  
  5.     QString shownName = curFile;
  6.  
  7.     if (curFile.isEmpty())
  8.         shownName = "Untitled.txt";
  9.  
  10.     setWindowFilePath(fileName);
  11.  
  12. }

Can anybody see what I did wrong? =/.

6 replies

September 12, 2011

Gerolf Gerolf
Robot Herder
3287 posts

perhaps you should use

  1. setWindowFilePath(fileName);

instead of

  1. setWindowFilePath(shownName);

Did you set a custom window title?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 12, 2011

RichardM198030 RichardM1980..
Lab Rat
95 posts

Gerolf wrote:
perhaps you should use

  1. setWindowFilePath(fileName);

instead of

  1. setWindowFilePath(shownName);

Did you set a custom window title?

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:

  1. setWindowTitle(tr("Text Editor -- Edit Text Files & Sources"));

IF that is what you’re referring to?

September 12, 2011

RichardM198030 RichardM1980..
Lab Rat
95 posts

Oh, and here’s an error message I’m getting, I’m running KDE, so it’s something X Related I Think:

  1. kfilemodule(5856) KSambaSharePrivate::findSmbConf: KSambaShare: Could not find smb.conf!
  2. X Error: BadWindow (invalid Window parameter) 3
  3.   Major opcode: 20 (X_GetProperty)
  4.   Resource id:  0x6400aaf
  5. X Error: BadWindow (invalid Window parameter) 3
  6.   Major opcode: 20 (X_GetProperty)
  7.   Resource id:  0x6406b4a

when I click the save Menu Item.

September 13, 2011

Volker Volker
Ant Farmer
5428 posts

The docs of QWidget::setWindowFilePath() [doc.qt.nokia.com] states it clearly:

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.

September 13, 2011

RichardM198030 RichardM1980..
Lab Rat
95 posts

Volker wrote:
The docs of QWidget::setWindowFilePath() [doc.qt.nokia.com] states it clearly:

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.

THanks, another thing I noticed, setWindowFilePath only makes sense in Windows, I have to use QFileInfo.

September 14, 2011

RichardM198030 RichardM1980..
Lab Rat
95 posts

Thanks for the replies, it was due to a custom window title, I took that out, and put

  1. Editor.setApplicationName("Text Editor");

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.

 
  ‹‹ Update the table’s ID column when you remove a row from a model.      "VIEWS" on same window ››

You must log in to post a reply. Not a member yet? Register here!