#ifndef ACREOPORTITEM_H
#define ACREOPORTITEM_H
#include<QDebug>
class ACReoportItem
{
public:
ACReoportItem();
enum ItemType
{
Sub_Result,
Sub_Param1,
Sub_Param2,
Sub_Item
};
virtual bool Query(ItemType type,void** ptr){
if(type==Sub_Item)
{
*ptr=this;
return true;
}
return false;
}
virtual void printData(){
qDebug()<<"ACReportItem!";
}
};
#endif
#ifndef ACREOPORTPARAM_H
#define ACREOPORTPARAM_H
#include"acreoportitem.h"
class ACReoportParam:public ACReoportItem
{
public:
ACReoportParam();
virtual bool Query(ItemType type,void** ptr){
if(type==Sub_Param1)
{
*ptr=this;
return true;
}
return false;
}
virtual void printData(){
qDebug()<<"ACReoportParam!";
}
};
#endif
#include <QCoreApplication>
#include<QList>
#include<QDebug>
#include"acreoportitem.h"
#include"acreoportparam.h"
#include"acreoportparam2.h"
#include"acreoportresult.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QList<ACReoportItem*> m_lstItem;
m_lstItem.append(new ACReoportItem());
m_lstItem.append(new ACReoportResult());
m_lstItem.append(new ACReoportParam());
m_lstItem.append(new ACReoportParam2());
m_lstItem.append(new ACReoportParam());
m_lstItem.append(new ACReoportParam2());
foreach(auto var ,m_lstItem)
{
ACReoportParam* param=Q_NULLPTR;
if( var->Query(ACReoportItem::ItemType::Sub_Param1,(void**)¶m))
{
param->printData();
}
}
return a.exec();
}