First-hand experience: a situation where sub-class details need to be obtained (five methods)

Source: Internet
Author: User

voidMyProgressBar::p aint (qpainter* painter,Constqstyleoptionviewitem& option,Constqmodelindex& index)Const{          //--------------------fetch data, test data---------------------------------        ConstQabstractitemmodel *item_model = Index.model ();//get the model based on the current index (including countless information)        intNrow = Index.row ();//Current line (the current line each time)//Note that this index.model is a function of the QT library itself:http://doc.qt.io/qt-4.8/qmodelindex.html        //Of course it can only return a qabstractitemmodel pointer, not the model that I inherited and modified, so it can't get the extra information I added//At this point, you have to drop the model to subclass to get exactly the information you need, about 5 ways//either use dynamic_cast, do rtti, either force the conversion (equivalent to static_cast), or record in advance the type pointers of my newly defined model in MyProgressBar, and don't know if Qt has any extra methods//The root cause of this problem is that the class library is not written by itself, it provides functions that can only get the parent class pointer}

First-hand experience: a situation where sub-class details need to be obtained (five methods)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.