Results 1 to 4 of 4

Thread: update tab's title when contents change

  1. #1
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default update tab's title when contents change

    Hello,

    I'm building (or rather playing with) a Qt 4.7 app which basically consists of a window that contains a menu bar, a tab widget and a status bar. Each tab in the tab widgets contains a plain text editor. So basically, it's a tabbed plain text editor
    Until now, I've managed to get it to create/open/save/close files, however, I haven't been able to change the tab text when the contents of the QPlainTextEdit change. It's simple when I open/save the file, but I don't know how to do it otherwise.
    Any ideas?
    In a SDI app I would normally do something like:
    Qt Code:
    1. connect(textEdit->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
    To copy to clipboard, switch view to plain text mode 
    but in this case, the text editor is no longer the central widget.
    I've tried (in the newFile method):
    Qt Code:
    1. EditorTab *editorTab = new EditorTab;
    2. int tabIndex = tabWidget->addTab(
    3. editorTab,
    4. editorTab->currentTitle
    5. );
    6. tabWidget->setCurrentIndex(tabIndex);
    7. connect(
    8. editorTab->document(),
    9. SIGNAL(contentsChanged()),
    10. this,
    11. SLOT(documentWasModified(tabIndex))
    12. );
    13. editorTab->setFocus();
    To copy to clipboard, switch view to plain text mode 
    documentWasModified is:
    Qt Code:
    1. qDebug("Tab %d changed", tabIndex);
    2. tabWidget->setTabText(tabIndex, "CHANGED");
    To copy to clipboard, switch view to plain text mode 
    And the result is
    Qt Code:
    1. Object::connect: No such slot MainWindow::documentWasModified(tabIndex) in ..\tabbedtextedit\mainwindow.cpp:85
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: update tab's title when contents change

    Well the QObject warning says it all. Your documentWasModified is not properly declared (as slot).

    You can't connect slots which require a parameter to a signal that doesn't give one!

    Make sure it looks something like this:

    Qt Code:
    1. class MainWindow : ..
    2. { Q_OBJECT
    3. public:
    4. ...
    5. protected slots:
    6. void documentWasModified();
    7.  
    8. };
    9.  
    10. void MainWindow::documentWasModified()
    11. {
    12. // get the tab index from your tabwidget currentIndex..
    13. }
    To copy to clipboard, switch view to plain text mode 
    HIH

    Johannes

  3. #3
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update tab's title when contents change

    Makes sense, thanks!

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    520
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 77 Times in 75 Posts

    Default Re: update tab's title when contents change

    Quote Originally Posted by alexei View Post
    Qt Code:
    1. connect(editorTab->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified(tabIndex)));
    To copy to clipboard, switch view to plain text mode 
    Hi, this won't work because you cannot pass arguments in the connect call. QSignalMapper might be helpful.

    Ginsengelf

Similar Threads

  1. QwtPlot Change Axis Title Alignment
    By deepy in forum Qwt
    Replies: 5
    Last Post: 20th October 2010, 13:40
  2. Replies: 1
    Last Post: 11th December 2009, 17:21
  3. how to change 'Thread title' in the forum
    By rishiraj in forum General Discussion
    Replies: 1
    Last Post: 1st April 2009, 07:00
  4. Title Bar Change setWindowModified
    By KaptainKarl in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2007, 17:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.