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 widgets in a QTabWidget
QtWS25 Last Chance

Accessing widgets in a QTabWidget

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 5.0k 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.
  • C Offline
    C Offline
    ChrisW67
    wrote on last edited by
    #2

    There should be two '=' signs in the if() of line 1 or you have an attempt at assignment that will fail.

    The attempt to access the webView member of the browseTab object will only succeed if it is a public member variable (which would not normally be the case).

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nicky j
      wrote on last edited by
      #3

      it won't compile and says browseTab does not refer to a value. The webView is a public member, the problem lies in trying to access the browseTab or appTab.

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #4

        What is the type of "browseTab"? Is it a widget, or a widget pointer?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nicky j
          wrote on last edited by
          #5

          widget. same with appTab.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #6

            That means you are trying to compare a value of widget type to a value of widget pointer type:
            [quote]
            @if(this->tabWidget->currentWidget() = browseTab)@
            [/quote]Basic rules of C++ comparisons:

            • Comparison is done using "==".
            • The values on the left and the right must be the same type.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nicky j
              wrote on last edited by
              #7

              So currentWidget() is a widget pointer? How do I get the widget type inside the tabWidget?

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #8

                [quote author="nicky j" date="1396838942"]So currentWidget() is a widget pointer?[/quote]This should answer your question: http://qt-project.org/doc/qt-5/qtabwidget.html#currentWidget
                [quote]How do I get the widget type inside the tabWidget?[/quote]I would do it the other way round -- get a pointer to your browseTab object, and use that in the comparison. Pointer values are integers after all, and it's straightforward to compare integers.

                Do you know how to use the ampersand (&) operator in C++?

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cbries
                  wrote on last edited by
                  #9

                  In few of my implementations I have a similar problem, I know what my tabs are include and just do a dynamic_cast for checking the widget type, e.g.

                  @
                  TcHmiFileTabWidget *TcHmiEditorView::fileTabWidget(int index)
                  {
                  QTabWidget *p = ui->tabFiles;

                  if(index < 0 || index > p->count()) {
                      return NULL;
                  }
                  
                  QWidget *w = p->widget(index);
                  if(w == NULL) { return NULL; }
                  
                  __TcHmiFileTabWidgetDummy *pdummy = dynamic_cast<__TcHmiFileTabWidgetDummy*>(w);
                  if(pdummy == NULL) { return NULL; }
                  
                  return pdummy->pFileTabWidget; 
                  

                  }
                  @

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #10

                    [quote author="cbries" date="1396854817"]In few of my implementations I have a similar problem, I know what my tabs are include and just do a dynamic_cast for checking the widget type[/quote]For QObjects (including QWidgets), I recommend qobject_cast over dynamic_cast. There are cases where dynamic_cast might fail but qobject_cast works. See http://qt-project.org/doc/qt-5/qobject.html#qobject_cast

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nicky j
                      wrote on last edited by
                      #11

                      No I don't really know how to use the ampersand

                      1 Reply Last reply
                      0
                      • JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #12

                        [quote author="nicky j" date="1397690719"]No I don't really know how to use the ampersand[/quote]It is a core part of C++. Qt makes extensive use of pointers and their related operators (including the '&' operator). Please take time to learn them: http://www.cplusplus.com/doc/tutorial/pointers/ -- it will make your life much easier.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        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