alexei
26th September 2010, 19:59
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:
connect(textEdit->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
but in this case, the text editor is no longer the central widget.
I've tried (in the newFile method):
EditorTab *editorTab = new EditorTab;
int tabIndex = tabWidget->addTab(
editorTab,
editorTab->currentTitle
);
tabWidget->setCurrentIndex(tabIndex);
connect(
editorTab->document(),
SIGNAL(contentsChanged()),
this,
SLOT(documentWasModified(tabIndex))
);
editorTab->setFocus();
documentWasModified is:
qDebug("Tab %d changed", tabIndex);
tabWidget->setTabText(tabIndex, "CHANGED");
And the result is
Object::connect: No such slot MainWindow::documentWasModified(tabIndex) in ..\tabbedtextedit\mainwindow.cpp:85:crying:
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:
connect(textEdit->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
but in this case, the text editor is no longer the central widget.
I've tried (in the newFile method):
EditorTab *editorTab = new EditorTab;
int tabIndex = tabWidget->addTab(
editorTab,
editorTab->currentTitle
);
tabWidget->setCurrentIndex(tabIndex);
connect(
editorTab->document(),
SIGNAL(contentsChanged()),
this,
SLOT(documentWasModified(tabIndex))
);
editorTab->setFocus();
documentWasModified is:
qDebug("Tab %d changed", tabIndex);
tabWidget->setTabText(tabIndex, "CHANGED");
And the result is
Object::connect: No such slot MainWindow::documentWasModified(tabIndex) in ..\tabbedtextedit\mainwindow.cpp:85:crying: