Important: Please read the Qt Code of Conduct -

where to #including QtObjects ? (Forward declaration)

  • Hi !!..

    I saw that could not possible to use forward declaration the way:

    class X{
    class QPushButton * getMyButton();
    #include "MyHeader.h"
    #include <QPushButton> 
    QPushButton * X::getMyButton(){
           return new QPushButton;

    It gives me the error "Return type of out-of-line definition of X::getMyButton() differs from that in the declaration"

    If I remove the "class" word and include the QPushButton directly on header, the problem goes away.... So this points me to a question...
    Do I´m forced to #include all my QtObjects inside the header file ?... or is there any way that I can do forward declaration in Qt ?..

    Thanks so much...

  • Lifetime Qt Champion

    When use pointers to widgets, you can forward like

    class QPushButton ; // forward
    class X{
    QPushButton * getMyButton();

  • Good, thanks friend...

Log in to reply