How do I get the currentTabName from a QTabWidget in Qt?

QTabWidget

has a property currentTabName

.

enter image description here

How can I access currentTabName

by code?

I need to check which tab is selected, but I cannot use the tab text ( tabText

) because it can be translatable and can change, and I don’t want to use the tab index ( currentIndex

) because the index might change in the future.

I am using Qt 5.3

+3


source to share


1 answer


As Chris Kawa said here is the object name of the current widget.

From the code I can get it like this:



QString currentTabName = tabWidget->currentWidget()->objectName();

      

Note . As the document shows, be sure to check nullptr

when using tabWidget->currentWidget()

.

+3


source







All Articles