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. Accessing attributes of Widgets

Accessing attributes of Widgets

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 890 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.
  • bart.hollisB Offline
    bart.hollisB Offline
    bart.hollis
    wrote on last edited by
    #1

    In the mainwindow.iu I have added, to the MainWindow, centralWidget a stackedWidget with multiple pages. There is also a pushbutton in the centralWidget. I have set the slot of the pushbutton which created an empty function in mainwindow.cpp. Now, I have to write the code to make each press of the button step forward through the pages of the stackedWidget. This requires that I get the current page or index of stackedWidget. Then I need to increment it and use the setCurrentIndex attribute.

    I cannot seem to do this! Can someone please give me the exact syntax for accessing these attributes?

    int currentPage = Ui_MainWindow::stackedWidget->currentIndex();
    

    seems to be the closest I can get.

    oPryzeLPO 1 Reply Last reply
    0
    • bart.hollisB bart.hollis

      In the mainwindow.iu I have added, to the MainWindow, centralWidget a stackedWidget with multiple pages. There is also a pushbutton in the centralWidget. I have set the slot of the pushbutton which created an empty function in mainwindow.cpp. Now, I have to write the code to make each press of the button step forward through the pages of the stackedWidget. This requires that I get the current page or index of stackedWidget. Then I need to increment it and use the setCurrentIndex attribute.

      I cannot seem to do this! Can someone please give me the exact syntax for accessing these attributes?

      int currentPage = Ui_MainWindow::stackedWidget->currentIndex();
      

      seems to be the closest I can get.

      oPryzeLPO Offline
      oPryzeLPO Offline
      oPryzeLP
      wrote on last edited by oPryzeLP
      #2

      @bart.hollis

      int currentPage = ui->stackedWidget->currentIndex();
      

      In your MainWindow.h, you have Ui::MainWindow *ui; as a private member variable. So you would use ui-> to access ui's members.

      1 Reply Last reply
      1
      • bart.hollisB Offline
        bart.hollisB Offline
        bart.hollis
        wrote on last edited by
        #3

        I get expected primary-expression before '->' token pointing at Ui->

        1 Reply Last reply
        0
        • oPryzeLPO Offline
          oPryzeLPO Offline
          oPryzeLP
          wrote on last edited by
          #4

          Make sure it's lowercase

          1 Reply Last reply
          2
          • bart.hollisB Offline
            bart.hollisB Offline
            bart.hollis
            wrote on last edited by
            #5

            Well, DUH! You did, after all show it as lower case.
            Thanks a bunch!

            1 Reply Last reply
            2
            • oPryzeLPO Offline
              oPryzeLPO Offline
              oPryzeLP
              wrote on last edited by
              #6

              Glad I could help :) For things like this, the documentation helps a ton as well as example projects. YouTube videos do pretty good as well.

              1 Reply Last reply
              0
              • bart.hollisB Offline
                bart.hollisB Offline
                bart.hollis
                wrote on last edited by
                #7

                It's good to know I won't make that mistake again!

                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