Results 1 to 6 of 6

Thread: Custom Widget constructor and registration problem.

  1. #1
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Custom Widget constructor and registration problem.

    Hello! I would like to create and register custom widget.


    Qt Code:
    1. class ResizeStackedWidget : public QStackedWidget
    2. {
    3. Q_CLASSINFO("ClassID", "ResizeStackedWidget") //Try to name class
    4. Q_OBJECT
    5. public:
    6. ResizeStackedWidget(QWidget * = 0, const char *name = 0 );
    7. ResizeStackedWidget(const ResizeStackedWidget& other ){} // Try to resolve no copy constructor
    8. void setCurrentIndex(int d);
    9. };
    10.  
    11. Q_DECLARE_METATYPE(ResizeStackedWidget* ); //I would like register it. Here error
    12.  
    13. ResizeStackedWidget::ResizeStackedWidget(QWidget * parent, const char *name )
    14. : QStackedWidget(parent)
    15. {
    16. }
    To copy to clipboard, switch view to plain text mode 

    And get this error "Error C4430: missing type specifier - int assumed. Note: C++ does not support default-int". Where is my mistackes?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    stepchik (11th March 2012)

  4. #3
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

    Qt Code:
    1. String cls = m_widget->metaObject()->className(); //cls = QStackedWidget, but i expected cls = ResizeStackedWidget
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. const QMetaObject *QStackedWidget::metaObject() const
    2. {
    3. return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
    4. }
    To copy to clipboard, switch view to plain text mode 

    If i step into metaObject() moc_qstackedwidget.cpp, but i suppose to call const QMetaObject *ResizeStackedWidget::metaObject() from moc_resizestackedwidget.cpp file ?

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

  6. #5
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget constructor and registration problem.

    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.
    Last edited by stepchik; 11th March 2012 at 09:43.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget constructor and registration problem.

    Quote Originally Posted by stepchik View Post
    I do Is it possible to realise some way?
    Simply remove your copy constructor or put it in private scope.

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Custom type registration on QVariant & toString()
    By zickedi in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2012, 01:34
  2. Custom Widget Constructor
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2010, 17:05
  3. Replies: 1
    Last Post: 22nd April 2010, 15:34
  4. Replies: 2
    Last Post: 22nd April 2010, 12:44
  5. DBus Registration problem
    By nrabara in forum Newbie
    Replies: 1
    Last Post: 30th April 2009, 11:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.