QTabWidget, Signal & Slot
-
Hi,
I have a QTabWidget with many page.
When the user is clicking on the first tab, I would like to update informations.
Moreover, I don't want to use a thread for it, to not overthread my applcation.This is what I did :
void MaFenetre::MaFenetre(): QWidget(){ allTab = new QTabWidget(this); // Some things QObject::connect(allTab,SIGNAL(currentChanged(int)),this,SLOT(isChanged(int))); } void MaFenetre::isChanged(int pos){ if(pos == 0){ this->updateMain(); } }
But this isn't doing what I want. I would like to change my tab, and then to execute the SLOT. This is doing the way.
Btw, I tryed also this, but this is giving the same result :void MaFenetre::isChanged(int pos){ if(pos == 0){ allTab->setCurrentIndex(0); this->updateMain(); } }
Thanks.
-
Hi and welcome to devnet,
What are the result you are expecting and what do you currently get ?
-
There's some kind of strange loop here.
Basically, when allTab has its index changed to 0, you set it to 0 again, and then call updateMain. What is the purpose of allTab in MaFenĂȘtre ?
-
Perhaps use a timer to delay the updating:
void MaFenetre::isChanged(int pos){ if(pos == 0) { QTimer::singleShot(200, this, &MaFenetre::updateMain); } }
@TheBadger said:
Perhaps use a timer to delay the updating:
void MaFenetre::isChanged(int pos){ if(pos == 0) { QTimer::singleShot(200, this, &MaFenetre::updateMain); } }
Thanks a lot, This solution worked fine for me !
@SGaist said:
There's some kind of strange loop here.
Basically, when allTab has its index changed to 0, you set it to 0 again, and then call updateMain. What is the purpose of allTab in MaFenĂȘtre ?
The fact is that it wasn't changing my tab until
updateMain();
finished. As my function take some time to be executed (2-3 seconds) when I was clicking on the index 0, i had a delay of 2-3 seconds before it switched to this tab. -
Should that updating happen only before that tab is shown ?
-
In that case why not trigger it through the showEvent of your widget ?
What makes that update take so much time ?
-
Are you downloading it each time ?
-
In that case why not add a spinner or busy indicator and show the widget directly ? It will at least remove the feeling that your application is stuck.