PDA

View Full Version : QTabWidget issue



cerr
3rd June 2010, 19:38
Hi There,

I got a little UI going with a QTabWidget on it. On the bottom I have
two buttons, "<< perevious" and "next>>" with which i wanna let the
user "scroll" through the tabs. I'm using following method to switch the tab but if i press the button, nothing happens:


connect(widget.NextBtn, SIGNAL(clicked()), this, SLOT(NextTab(int current)));
...
...
void HelloForm::NextTab(void){
if (widget.tabWidget->currentIndex()!=-1)
{
widget.tabWidget->setCurrentIndex(this->TabIndex=+1);
}
}

What am I doing wrongly?

Thank you for help!
roN

salmanmanekia
3rd June 2010, 20:27
Hi,
the slot statement in the connect isnt right ,there is no variable name in the paranthesis in connect it should be like ...SLOT(NextTab(int)) ....and for the same function you are using int in the paranthesis while in the function itself it is void..

cerr
3rd June 2010, 21:45
Hi,
the slot statement in the connect isnt right ,there is no variable name in the paranthesis in connect it should be like ...SLOT(NextTab(int)) ....and for the same function you are using int in the paranthesis while in the function itself it is void..

Great, thank you, I changed this to :(
current code:

connect(widget.NextBtn, SIGNAL(clicked()), this, SLOT(NextTab()));
..
..
void HelloForm::NextTab(void){
if (widget.tabWidget->currentIndex()!=-1)
{
widget.tabWidget->setCurrentIndex(this->TabIndex=+1);
}
}



And got it partially working. I get it to go to tab2 but for some reason it doesn't go to the third one... :(
And also my perevious button isn't working at all:

connect(widget.PereviousBtn, SIGNAL(clicked()), this, SLOT(PereviousTab()));
...
...
void HelloForm::PereviousTab(void){
if (widget.tabWidget->currentIndex()!=-1)
{
widget.tabWidget->setCurrentIndex(this->TabIndex=-1);
}
}


Any more clues?

Thanks,
roN

SixDegrees
3rd June 2010, 22:00
Why are you setting the index on widget.tabWidget, but getting the index from this->TabIndex?

Try splitting things up into two calls: the first to obtain the current index, the second to set it. Then print out the values at each step to confirm that A) your slots are getting called as you expect, and B) the correct values are being obtained and computed.