Results 1 to 6 of 6

Thread: Custom Widget constructor and registration problem.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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.

Similar Threads

  1. Custom type registration on QVariant & toString()
    By zickedi in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2012, 00:34
  2. Custom Widget Constructor
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2010, 16:05
  3. Replies: 1
    Last Post: 22nd April 2010, 14:34
  4. Replies: 2
    Last Post: 22nd April 2010, 11:44
  5. DBus Registration problem
    By nrabara in forum Newbie
    Replies: 1
    Last Post: 30th April 2009, 10: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.