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;
    [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&#40;fileName&#41;;
    statusBar(&#41;->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(&#41;)
        shownName = "Untitled.txt";
    
    setWindowFilePath(fileName);
    

    }
    [/code]

    Can anybody see what I did wrong? =/.



  • perhaps you should use

    @
    setWindowFilePath(fileName);
    @

    instead of

    @
    setWindowFilePath(shownName);
    @

    Did you set a custom window title?



  • [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?



  • 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.



  • 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 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.