acsessing QTextEdit from QTabWidget
so i'm making a small editor for FASM with Qt, i am building over the Syntax Highlighter Example that the Qt SDK comes with. i have syntax highlighting down and file I/O is going really well but i want to have tabs to mange multiple files at the same time. at first i thought "ok that's easy i just make QTabWidget my central widget and add QTextEdit child's to it." the issue with this is that i cant find a way to access the actual QTextEdit becuase i can only access the QWidget of the tab. im not sure how QTextEdit works witch makes finding a solution some what difficult. if there is a way to alter the actual Widget indexed by each tab as a QTextEdit and maintain all needed information to display them correctly.
here is some code showing my problem, how do i alter the properties of the current widget as a QTextEdit.
Code:
void MainWindow
::openFile(const QString &path
) {
QTextEdit Tabed_Editor
(Tabs
->currentWidget
());
if (fileName.isNull())
tr("Open File"), "", "ASM Files (*.asm *.inc);; All(*.*)");
if (!fileName.isEmpty()) {
Tabed_Editor.setPlainText(file.readAll()); ///here this will not actully edit the current widit as it is a copy but how else would i edit it?
}
}
Re: acsessing QTextEdit from QTabWidget
Code:
QTextEdit *editor
= qobject_cast<QTextEdit
*>
(Tabs
->currentWidget
());
...
editor->setPlainText(...);
Re: acsessing QTextEdit from QTabWidget
thanks, i thought this would use a template but i had not seen any documentation that would allow for this kind of conversion (i was only looking within the classes them self's), thanks again :)
Re: acsessing QTextEdit from QTabWidget
Just a note:
Always check if the object exists after casting and before using it. Otherwise you'll get a crash.