How to know the current tab selected
I've created a qtabwidget with 4 tabs inside it, i need to know which current tab is
currently selected by the user, the way i thought to do that was to have a call to the
connect, something like this:
connect( tab1pressed, SIGNAL(clicked()), this, SLOT( function_something1() ));
connect( tab2pressed, SIGNAL(clicked()), this, SLOT( function_something2() ));
.....
Problem is i can't see what is the correct function to call to do the tab1pressed part,
tabWidget->currentWidget() something? or there's a total different way to do this?
Thanks in advance.
Re: How to know the current tab selected
Re: How to know the current tab selected
Quote:
Originally Posted by
jpn
Thanks, i tried to use the tabWidget->currentchanged as a signal in connect, like this:
connect( tabWidget->currentWidget(), SIGNAL(tabWidget->currentChanged(1)), this, SLOT( function_something1() ));
but it isn't working, maybe instead of tabWidget->currentWidget() i must use other thing?
Re: How to know the current tab selected
You must fix connect as following:
connect( tabWidget, SIGNAL(tabWidget->currentChanged(int)), this, SLOT( function_something1() ));
or
connect( tabWidget, SIGNAL(tabWidget->currentChanged(int)), this, SLOT( function_something2(int) ));
function_something1() used if you not need parameter in currentChanged(int)
Re: How to know the current tab selected
This won't work. This will:
Code:
connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(activateTab(int)));
//...
void SomeClass::activateTab(int index){
qDebug("%d tab selected", index);
}
Re: How to know the current tab selected
Well, actually both examples aren't working, it never enters the function_something/activatetab.
More of my code
Code:
{
tabWidget->addTab( new Tab_1, tr("Tab_1") );
tabWidget->addTab( new Tab_2, tr("Tab_2") );
tabWidget->addTab( new Tab_3_Tab, tr("Tab_3") );
tabWidget->addTab( new Tab_4, tr("Tab_4") );
//then i used one of connect examples
connect( tabWidget, SIGNAL(tabWidget->currentChanged(int)), this, SLOT( function_something1() ));
//or
connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(activateTab(int)));
mainLayout
->setSizeConstraint
( QLayout::SetFixedSize );
mainLayout->addWidget(tabWidget);
setLayout(mainLayout);
}
...
Re: How to know the current tab selected
Please, use "[ code ]" tags around your code postings to make them readable. Have you declared the corresponding slot? Do you have the required Q_OBJECT macro?
Code:
class My_tab ...
{
QOBJECT // <--
...
private slots: // <--
void activateTab(int idx); // <--
...
};
Re: How to know the current tab selected
Quote:
Originally Posted by
jpn
Please, use "[ code ]" tags around your code postings to make them readable. Have you declared the corresponding slot? Do you have the required Q_OBJECT macro?
Code:
class My_tab ...
{
QOBJECT // <--
...
private slots: // <--
void activateTab(int idx); // <--
...
};
Yes, i've the QOBJECT, and the activeTab defined as private slot. :confused:
Re: How to know the current tab selected
So you're using Windows?
- add "CONFIG += console" to the .pro file
- re-run qmake & rebuild the application
- run the application and see the command line for the reason why QObject::connect() fails
Re: How to know the current tab selected
Quote:
Originally Posted by
Mrdata
connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(activateTab(int)));
Probably it should be:
Code:
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(activateTab(int)));
Re: How to know the current tab selected
Re: How to know the current tab selected
Quote:
Originally Posted by
jpn
True, somehow I always think that it's an equivalent of "connect(sender, signal, sender, slot, type)" (which obviously doesn't have much sense).