Custom Widget constructor and registration problem.
Hello! I would like to create and register custom widget.
Code:
{
Q_CLASSINFO("ClassID", "ResizeStackedWidget") //Try to name class
Q_OBJECT
public:
ResizeStackedWidget
(QWidget * = 0,
const char *name
= 0 );
ResizeStackedWidget(const ResizeStackedWidget& other ){} // Try to resolve no copy constructor
void setCurrentIndex(int d);
};
Q_DECLARE_METATYPE(ResizeStackedWidget* ); //I would like register it. Here error
ResizeStackedWidget
::ResizeStackedWidget(QWidget * parent,
const char *name
){
}
And get this error "Error C4430: missing type specifier - int assumed. Note: C++ does not support default-int". Where is my mistackes?
Re: Custom Widget constructor and registration problem.
You don't need to call Q_DECLARE_METATYPE on your custom widget - since it is a QObject already (its a sublcass of QStackedWidget).
Q_DECLARE_METATYPE is for non Qt types that you would like to add to use with the signal slot system and QVariant usage.
Re: Custom Widget constructor and registration problem.
But somewhere in my program i have getType() function. Depends from widget type i do some actions. The problem is ResizeStackedWidget detect as base class QStackedWidget.
Code:
String cls = m_widget->metaObject()->className(); //cls = QStackedWidget, but i expected cls = ResizeStackedWidget
Code:
{
return QObject::d_ptr->metaObject ?
QObject::d_ptr->metaObject
: &staticMetaObject;
}
If i step into metaObject() moc_qstackedwidget.cpp, but i suppose to call const QMetaObject *ResizeStackedWidget::metaObject() from moc_resizestackedwidget.cpp file ?
Re: Custom Widget constructor and registration problem.
A copy constructor on a QObject does not make much sense. Are you trying to achieve what the Q_DISABLE_COPY macro does?
Other than that, your code snippet generates no errors here.
Re: Custom Widget constructor and registration problem.
Quote:
Are you trying to achieve what the Q_DISABLE_COPY macro does?
I do:) Is it possible to realise some way?
Added after 37 minutes:
Does this mean I have to create my own Custom Widget is not inherited from the some QWidget(QStackedWidget in my case)?
Why it works(constructor class ResizeStackedWidget : public QStackedWidget) as plugin in Qt Designer? I haven't errors.
Re: Custom Widget constructor and registration problem.
Quote:
Originally Posted by
stepchik
I do:) Is it possible to realise some way?
Simply remove your copy constructor or put it in private scope.
Quote:
Does this mean I have to create my own Custom Widget is not inherited from the some QWidget(QStackedWidget in my case)?
Why it works(constructor class ResizeStackedWidget : public QStackedWidget) as plugin in Qt Designer? I haven't errors.
We don't know what you are trying to do so it is hard to answer those questions. My guess is that you should use virtual methods instead of checking the class name at runtime. Especially that if someone inherits your class and uses the Q_OBJECT macro, the meta-object will point to the inherited class and not yours.