Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. where to #including QtObjects ? (Forward declaration)

where to #including QtObjects ? (Forward declaration)

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 181 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by U7Development
    #1

    Hi !!..

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

    //MyHeader.h
    class X{
    class QPushButton * getMyButton();
    };
    
    //Source
    #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...

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      When use pointers to widgets, you can forward like

      class QPushButton ; // forward
      
      //MyHeader.h
      class X{
      QPushButton * getMyButton();
      };
      
      
      1 Reply Last reply
      6
      • U Offline
        U Offline
        U7Development
        wrote on last edited by
        #3

        Good, thanks friend...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved