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. Forward Declaration error
Qt 6.11 is out! See what's new in the release blog

Forward Declaration error

Scheduled Pinned Locked Moved General and Desktop
26 Posts 4 Posters 27.0k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pragati
    wrote on last edited by
    #21

    I did changed to Namespace DMM...but prob is I have to create an instance of this DMM in other directory class like this:
    Start.h
    @
    #ifndef START_H
    #define START_H

    #include "../../DMM/Include/DMM.h"

    /****************************************************************************/
    /**

    • \brief This class handles the initialization of the user interface.
      /
      /
      ***************************************************************************/
      namespace Start {

    class Startup : public QObject
    {
    Q_OBJECT

    public:
    Startup();
    virtual ~Startup();
    void GuiInit();

    private:

    Ui::DMMMenu *MainWindow;

    };

    }

    #endif // START_H
    @

    Start.cpp:

    @

    #include "../../Start/Include/Start.h"

    namespace Start {

    Startup::Startup() : QObject()
    {
    
    // GUI components
    
    MainWindow = new DMM::DMMMenu();
    

    }

    Startup::~Startup()
    {
    try {
    // GUI Components

        delete MainWindow;
    }
    catch (...) {}
    

    }

    /***************************************************************************/
    /
    !

    • \brief Initializes the user interface
      /
      /
      ***************************************************************************/
      void Startup::GuiInit()
      {
      MainWindow->show();

    }

    }

    @

    So now I am getting errors like these upon changing namespace to DMM:

    1. /home/pragati/MultiFuncTester/Components/Start/Build/../Source/Start.cpp:-1: In constructor 'Start::Startup::Startup()':

    /home/pragati/MultiFuncTester/Components/Start/Build/../Source/Start.cpp:12: error: cannot convert 'DMM::DMMMenu' to 'Ui::DMMMenu*' in assignment*

    2./home/pragati/MultiFuncTester/Components/Start/Build/../Source/Start.cpp:35: error: invalid use of incomplete type 'struct Ui::DMMMenu'

    3./home/pragati/MultiFuncTester/Components/Start/Build/../../DMM/Include/DMM.h:9: error: forward declaration of 'struct Ui::DMMMenu'

    1 Reply Last reply
    0
    • R Offline
      R Offline
      r3willia
      wrote on last edited by
      #22

      That's good - it means the compiler's got past the problem you were having before - now you've got the problem that you're using the wrong type for your member of Start::Startup.

      I expect you want Start::Startup's declaration to read:

      @class Startup : public QObject
      {
      Q_OBJECT

      public:
      Startup();
      virtual ~Startup();
      void GuiInit();

      private:

      DMM::DMMMenu *MainWindow;

      };@

      DMM::DMMMenu has a Ui::DMMMenu, but DMM::DMMMenu is not a Ui::DMMMenu (to use Object-orientated is-a / has-a terminology).

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pragati
        wrote on last edited by
        #23

        :(

        I used it already before but as soon as I do this:
        @DMM::DMMMenu *MainWindow;
        @
        I get error that
        1./home/pragati/MultiFuncTester/Components/Start/Build/../../Start/Include/Start.h:27: error: 'DMM' does not name a type

        and

        2./home/pragati/MultiFuncTester/Components/Start/Build/../Source/Start.cpp:35: error: 'MainWindow' was not declared in this scope

        1 Reply Last reply
        0
        • R Offline
          R Offline
          r3willia
          wrote on last edited by
          #24

          You're referencing DMM from within the namespace Start; it's possible you may have to be specific i.e. declare the parameter:
          @::DMM::DMMMenu *MainWindow;@

          Also make certain that "../../DMM/Include/DMM.h" does indeed define DMM::DMMMenu.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pragati
            wrote on last edited by
            #25

            r3Willia,

            I am still getting errors but not regarding this....anyways thank you so much...you came when I was not getting help from anyone....Thank you so much....wish I cud have personally thanked you...bt anyways....all the best and again ty....

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pragati
              wrote on last edited by
              #26

              hi...

              Everything is working fine until when I write in main. In main I included one of the subdirectory's .h file and wrote some function like this I am posting here both the codes of main and that directory....

              Error I am getting is :

              /home/pragati/MultiFuncTester/Components/Main/Source/Main.cpp:-1: error: undefined reference to `Start::Startup::Startup()'

              /home/pragati/MultiFuncTester/Components/Main/Source/Main.cpp:-1: error: undefined reference to `Start::Startup::GuiInit()'
              /home/pragati/MultiFuncTester/Components/Main/Source

              /Main.cpp:-1: error: undefined reference to `Start::Startup::~Startup()'

              Similiar error for GuiInit....

              Start.h

              @
              #ifndef START_H
              #define START_H

              #include "../../DMM/Include/DMM.h"

              /****************************************************************************/
              /**

              • \brief This class handles the initialization of the user interface.
                /
                /
                ***************************************************************************/
                namespace Start {

              class Startup : public QObject
              {
              Q_OBJECT

              public:

              Startup();
              virtual ~Startup();
              void GuiInit();

              private:

              DMM::DMMMenu *MainWindow;

              };

              }

              #endif // START_H

              @

              Start.cpp

              @

              #include "../../Start/Include/Start.h"
              namespace Start {

              Startup::Startup() : QObject()
              {

              // // GUI components

              MainWindow = new DMM::DMMMenu();

              }

              /***************************************************************************/
              /
              !

              • \brief Initializes the user interface
                /
                /
                ***************************************************************************/
                void Startup::GuiInit()
                {
                MainWindow->show();

              }

              }
              @

              Main.cpp

              @
              #include "../../Start/Include/Start.h"
              #include <QApplication>
              #include <QtGui>

              int main(int argc, char *argv[])

              {
              QApplication app(argc, argv);
              Start::Startup start;
              start.GuiInit();
              return app.exec();
              }

              @

              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