[SOLVED] QTabWidget->currentWidget() returns NULL
-
Hi!, I'm writing a text editor in qt (4.8.5) mainly for learning. I have QTextEdit widgets inside a QTabWidget. However when I go to access the QTextEdit using the currentWidget function it returns a NULL.
A little snippet:
_QWidget *current = maintab->currentWidget();
if(current == NULL)
qDebug() << "NULL";
else
qDebug() << current->metaObject()->className();
_
The output that I get is NULL where I'm expecting QTextEdit. I create the widget using:maintab->addTab(new QTextEdit(), "New File");
What am I doing wrong??
-
The documentation says the following:
bq. Returns a pointer to the page currently being displayed by the tab dialog. The tab dialog does its best to make sure that this value is never 0 (but if you try hard enough, it can be).[/quote]
I guess you tried hard enough, congratulations.
Did you actively switch to that current widget? Is the whole TabWidget visible including the tabbar and one if its widgets?
-
Never mind found the problem. I feel kinda silly.. I was trying to extract qtextedit in a function that is called before any new tabs are even made. Silly me.....
-
Two small things to add:
-
There is a code-tag (last button for me) which would have made your code above a lot easier to read.
-
It is good habit to edit the title of your threads and put a [Solved] in front once a problem is solved. Would be a lot easier to navigate in here if everybody did that.
Happy coding! :)
-
-
Cool, I'll keep that in mind.