Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Window Title not showing name of file [Solved]
Forum Updated to NodeBB v4.3 + New Features

Window Title not showing name of file [Solved]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RichardM198030
    wrote on 12 Sept 2011, 16:56 last edited by
    #1

    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? =/.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 12 Sept 2011, 17:14 last edited by
      #2

      perhaps you should use

      @
      setWindowFilePath(fileName);
      @

      instead of

      @
      setWindowFilePath(shownName);
      @

      Did you set a custom window title?

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RichardM198030
        wrote on 12 Sept 2011, 17:22 last edited by
        #3

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

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RichardM198030
          wrote on 12 Sept 2011, 17:31 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on 13 Sept 2011, 06:25 last edited by
            #5

            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.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RichardM198030
              wrote on 13 Sept 2011, 18:36 last edited by
              #6

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

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RichardM198030
                wrote on 14 Sept 2011, 04:53 last edited by
                #7

                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 Reply Last reply
                0

                1/7

                12 Sept 2011, 16:56

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved