Unsolved 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 ?
-
Hi,
I expect to change of tab, and then, to update the page.
At the moment, when I click on my tab, it is updating the tab, and then, changing the tab. -
Perhaps use a timer to delay the updating:
void MaFenetre::isChanged(int pos){ if(pos == 0) { QTimer::singleShot(200, this, &MaFenetre::updateMain); } }
-
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 ?
-
@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 ?
-
@SGaist said:
Should that updating happen only before that tab is shown ?
Kind of. It's useless to update it while the user don't want to see them.
-
In that case why not trigger it through the showEvent of your widget ?
What makes that update take so much time ?
-
I apologize for the delay.
I'm downloading a picture during the update, that's why it is taking so much time.
Of course, I could do a QThread, but I try to use them as less as possible to not over thread. -
Are you downloading it each time ?
-
Yes, I want to download it again each time I'm back on my update tab.
-
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.