How to override (re-implement) a member function in QFileSystemModel

前端 未结 2 901
遇见更好的自我
遇见更好的自我 2021-01-15 08:51

I\'ve been struggling with this for a while.

Qt\'s QFileSystemModel is really slow when fetching several hundred files because of a really bad icon fetc

2条回答
  •  忘掉有多难
    2021-01-15 09:04

    If a function in a base class is virtual then it is virtual in derived classes as well. The following will print "C":

    #include 
    
    class A {
    public:
      virtual void data() = 0;
    };
    
    class B: public A {
    public:
      void data() { std::cout << "B\n"; }
    };
    
    class C: public B {
    public:
      void data() { std::cout << "C\n"; }
    };
    
    int
    main() {
      C c;
      A *a = &c;
      a->data();
    
      return 0;
    }
    

    QFileSystemDialog is derived from QAbstractItemModel in which data() is pure virtual. You couldn't even instatiate the former if it didn't override data() with its own implementation.

    See http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#data

提交回复
热议问题