Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTabWidget, Signal & Slot

QTabWidget, Signal & Slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++signal & slotqtabwidget
13 Posts 3 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xavier59
    wrote on last edited by koahnig
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What are the result you are expecting and what do you currently get ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • X Offline
        X Offline
        Xavier59
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • TheBadgerT Offline
          TheBadgerT Offline
          TheBadger
          wrote on last edited by
          #4

          Perhaps use a timer to delay the updating:

          void MaFenetre::isChanged(int pos){
              if(pos == 0) {
                  QTimer::singleShot(200, this, &MaFenetre::updateMain);
              }
          }
          

          Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

          X 1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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 ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • TheBadgerT TheBadger

              Perhaps use a timer to delay the updating:

              void MaFenetre::isChanged(int pos){
                  if(pos == 0) {
                      QTimer::singleShot(200, this, &MaFenetre::updateMain);
                  }
              }
              
              X Offline
              X Offline
              Xavier59
              wrote on last edited by
              #6

              @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.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Should that updating happen only before that tab is shown ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                X 1 Reply Last reply
                0
                • SGaistS SGaist

                  Should that updating happen only before that tab is shown ?

                  X Offline
                  X Offline
                  Xavier59
                  wrote on last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    In that case why not trigger it through the showEvent of your widget ?

                    What makes that update take so much time ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      Xavier59
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Are you downloading it each time ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • X Offline
                          X Offline
                          Xavier59
                          wrote on last edited by
                          #12

                          Yes, I want to download it again each time I'm back on my update tab.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved