Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to extend method expanded in QTreeView
Forum Updated to NodeBB v4.3 + New Features

How to extend method expanded in QTreeView

Scheduled Pinned Locked Moved Language Bindings
7 Posts 3 Posters 4.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    shen yang
    wrote on 31 Aug 2011, 04:20 last edited by
    #1

    I want overwrite QTreeView
    @class SelfDifineTree : public QTreeView{
    public:
    SelfDifineTree();
    virtual ~SelfDifineTree();
    Q_SIGNALS:
    void expanded(const QModelIndex &index);
    @
    but got a error
    @D:\bak\mytreewindow\mytreewindow-build-desktop......\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui\qtreeview.h:151: candidates are: void QTreeView::expanded(const QModelIndex&)@

    can anyone help me on this problem?thx a lot

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on 31 Aug 2011, 05:06 last edited by
      #2

      The signal "expanded is already declared at class QTreeView":http://doc.qt.nokia.com/latest/qtreeview.html#expanded which is inherited by your class SelfDifineTree.

      http://anavi.org/

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shen yang
        wrote on 31 Aug 2011, 05:19 last edited by
        #3

        Thx for your reply, it is true that expanded is already defined, and this is also my purpose, I want do overwrite this method
        @
        void SelfDifineTree::expanded(const QModelIndex &index){
        //to do somthing
        this->QTreeView::expanded(&index);
        }
        @
        is this possible?
        [quote author="leon.anavi" date="1314767211"]The signal "expanded is already declared at class QTreeView":http://doc.qt.nokia.com/latest/qtreeview.html#expanded which is inherited by your class SelfDifineTree.[/quote]

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on 31 Aug 2011, 05:27 last edited by
          #4

          [quote author="shen yang" date="1314767996"]Thx for your reply, it is true that expanded is already defined, and this is also my purpose, I want do overwrite this method
          [/quote]

          No, you can't because it is not declared as virtual and it is a signal.

          http://anavi.org/

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 31 Aug 2011, 05:59 last edited by
            #5

            expanded() is a signal, and is as leon.anavi rightly points out, not virtual. Instead of subclassing and reimplenting the method, why not simply create a new slot in your subclass, and connect to the signal instead?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              shen yang
              wrote on 31 Aug 2011, 06:21 last edited by
              #6

              Thx anyway, now I'm wondering what make this method expanded can not been overwrite, I can only see
              @

              define Q_SIGNALS protected

              @
              for this, I write a small test, when I call testp(), it call the testprotected() in childclass, really puzzled.
              parentclass.h
              @
              class ParentClass{
              public:
              ParentClass();
              virtual ~ParentClass();
              protected:
              void testprotected();
              };

              @
              childclass.h
              @
              #include "parentclass.h"

              class ChildClass:public ParentClass{
              public:
              ChildClass();
              void testp();
              virtual ~ChildClass();

              protected:
              void testprotected();
              };

              @
              parentclass.cpp
              @
              #include "parentclass.h"
              #include <QDebug>

              ParentClass:: ParentClass (){

                  qDebug()<<"Build Parent";
              }
              

              ParentClass:: ~ParentClass(){
              qDebug()<<"delete parent";
              }

              void ParentClass:: testprotected(){
              qDebug()<<"testprotected parent";
              }

              @
              childclass.cpp
              @
              #include "childclass.h"
              #include <QDebug>

              ChildClass::ChildClass(){
              }
              ChildClass::~ChildClass(){
              }

              void ChildClass:: testprotected(){
              qDebug()<<"testprotected child";
              }

              void ChildClass:: testp(){
              testprotected();
              }
              @
              And even change to this, this small test can also,run.
              @

              define Q_SIGNALS protected

              class ParentClass{
              public:
              ParentClass();
              virtual ~ParentClass();
              Q_SIGNALS:
              void testprotected();
              };
              @

              [quote author="leon.anavi" date="1314768472"]
              [quote author="shen yang" date="1314767996"]Thx for your reply, it is true that expanded is already defined, and this is also my purpose, I want do overwrite this method
              [/quote]

              No, you can't because it is not declared as virtual and it is a signal.
              [/quote]

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shen yang
                wrote on 31 Aug 2011, 06:30 last edited by
                #7

                Got it, thx.
                [quote author="Andre" date="1314770348"]expanded() is a signal, and is as leon.anavi rightly points out, not virtual. Instead of subclassing and reimplenting the method, why not simply create a new slot in your subclass, and connect to the signal instead?[/quote]

                1 Reply Last reply
                0

                5/7

                31 Aug 2011, 05:59

                • Login

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