LibsElementSelector *libs=qobject_cast<LibsElementSelector*>(widget);
LibsElementSelector *libs=(LibsElementSelector*)widget;
widget->metaObject()->className();
QList <LibsElementSelector*> list=superWidget->findChildren <LibsElementSelector*>();
QList<QWidget*> list=superWidget->findChildren<QWidget*>(); LibsElementSelector *l; for(int i=0;i<list.count();i++){ if(QString::compare(list.at(i)->metaObject()->className(),"LibsElementSelector")==0){ l=(LibsElementSelector*)list.at(i); //... } }
if(QString::compare(list.at(i)->metaObject()->className(),"LibsElementSelector")==0){ l=dynamic_cast<LibsElementSelector*>(list.at(i)); qDebug() << "dynamic_cast" << l; l=qobject_cast<LibsElementSelector*>(list.at(i)); qDebug() << "qobject_cast" << l; l=(LibsElementSelector*)list.at(i); qDebug() << "(LibsElementSelector*)" << l; //... }
dynamic_cast LibsElementSelector(0xa7588d0, name = "libClient") qobject_cast QObject(0x0) (LibsElementSelector*) LibsElementSelector(0xa7588d0, name = "libClient")
class LibsElementSelector : public QFrame{ Q_OBJECT Q_PROPERTY(int lib_head_id READ getHeadId WRITE setHeadId)public: LibsElementSelector(QWidget *parent = 0); ~LibsElementSelector(); void setModel(libModel* model); void setModel(libPool *pool, int head); libModel* model(){ return lModel; } void setPool(libPool *pool){ setModel(pool,headId); } QModelIndex currentIndex(); QVariant currentData(int role=libModel::idRole); void setCurrentData(const QVariant &data, int role=libModel::idRole); int getHeadId(){return headId;} void setHeadId(int i){ headId=i; if(modelsPool)setModel(modelsPool, headId); }private: QLineEdit *line; QPushButton *button; QTreeView *view; QByteArray viewGeometry; QModelIndex index; libModel *lModel; int savedX; int savedY; int headId; libPool *modelsPool;public slots: void setCurrentIndex(const QModelIndex &idx);private slots: void showView(); void hideView();signals: void currentIndexChanged(const QModelIndex &idx);};
class IFace {public slots:virtual slot() {}};