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. [SOLVED] ISO C++ forbids declaration of 'MenuAdm' with no type in file of menudaftar.h
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] ISO C++ forbids declaration of 'MenuAdm' with no type in file of menudaftar.h

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 7.9k 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.
  • Y Offline
    Y Offline
    yola-yoli
    wrote on last edited by
    #1

    Hello Everybody..
    I get an error: ISO C++ forbids declaration of 'MenuAdm' with no type in file of menudaftar.h.

    @
    #ifndef MENUADM_H
    #define MENUADM_H
    #include <QMainWindow>
    #include <menudaftar.h>

    namespace Ui {
    class MenuAdm;
    }
    class MenuAdm : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MenuAdm(QWidget *parent = 0);
    MenuDaftar *objmain7;
    ~MenuAdm();
    private slots:
    void btnaction6();
    private:
    Ui::MenuAdm *ui;
    };
    #endif // MENUADM_H
    @

    Menuadm.cpp
    @#include "menuadm.h"
    #include "ui_menuadm.h"

    MenuAdm::MenuAdm(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MenuAdm)
    {
    ui->setupUi(this);
    connect(ui->pushButtonDaftar,SIGNAL(clicked()),this,SLOT(btnaction6()));

    void MenuAdm::btnaction6()
    {
        objmain7 = new MenuDaftar;
        objmain7->showFullScreen();
    }
    

    MenuAdm::~MenuAdm()
    {
    delete ui;
    }
    @

    Menudaftar.h
    @#ifndef MENUDAFTAR_H
    #define MENUDAFTAR_H
    #include <QMainWindow>
    #include <menuadm.h>

    namespace Ui {
    class MenuDaftar;
    }
    class MenuDaftar : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MenuDaftar(QWidget *parent = 0);
    MenuAdm *objmain; //this is an error
    ~MenuDaftar();

    private slots:
    void btnaction();

    private:
    Ui::MenuDaftar *ui;
    };
    #endif // MENUDAFTAR_H
    @

    Menudaftar.cpp
    @#include "menudaftar.h"
    #include "ui_menudaftar.h"

    MenuDaftar::MenuDaftar(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MenuDaftar)
    {
    ui->setupUi(this);
    connect(ui->pushButtonCancel,SIGNAL(clicked()),this,SLOT(btnaction()));
    //pushButtonCancel is objectName of Push Button
    }
    void MenuDaftar::btnaction() //this method used to create back function to MenuAdm,
    {
    objmain = new MenuAdm;
    objmain->showFullScreen();
    }
    MenuDaftar::~MenuDaftar()
    {
    delete ui;
    }
    @

    Thanks for help.

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      You'd probably need a "using namespace Ui" in your cpp files.

      Edit : corrected typo in namespace name (Ui, not UI).

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yola-yoli
        wrote on last edited by
        #3

        only using namespace UI?

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          Your two classes MenuDaftar and MenuAdm are defined in the Ui namespace (looking at your headers). This namespace must therefore be mentioned in the cpp file as well, otherwise the compiler thinks you're defining other classes and the ones from the headers are left undefined.

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RaubTieR
            wrote on last edited by
            #5

            In your Menuadm.cpp code I unsee the closing brace for block started at line 7, may be this is the problem?

            Also in this case that is possible to write into Menudaftar.h the further declaration of class MenuAdm, since you use pointer:
            @namespace Ui {
            class MenuDaftar;
            class MenuAdm; // adding here
            }
            // or may be outside, I dont actually know, but 73% adding outside is better IMO@

            and then you take
            @#include <menuadm.h>@

            to your Menudaftar.cpp file. At least it might solve the error in menudaftar.h, I hope.

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yola-yoli
              wrote on last edited by
              #6

              okey, i will try it now...
              thanks for help..

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yola-yoli
                wrote on last edited by
                #7

                Thanks for help.
                I can solve the problem with your advice, RaubTieR.

                This is the right source code.

                Menuadm.h
                @
                #ifndef MENUADM_H
                #define MENUADM_H
                #include <QMainWindow>
                #include <menudaftar.h>

                namespace Ui {
                class MenuAdm;
                }

                class MenuDaftar; //add this code

                class MenuAdm : public QMainWindow
                {
                Q_OBJECT
                public:
                explicit MenuAdm(QWidget *parent = 0);
                MenuDaftar *objmain7;
                ~MenuAdm();
                private slots:
                void btnaction6();
                private:
                Ui::MenuAdm *ui;
                };
                #endif // MENUADM_H
                @

                Menudaftar.h
                @
                #ifndef MENUDAFTAR_H
                #define MENUDAFTAR_H
                #include <QMainWindow>
                #include <menuadm.h>

                namespace Ui {
                class MenuDaftar;
                }

                class MenuAdm; //add this code

                class MenuDaftar : public QMainWindow
                {
                Q_OBJECT
                public:
                explicit MenuDaftar(QWidget *parent = 0);
                MenuAdm *objmain; //this is an error
                ~MenuDaftar();

                private slots:
                     void btnaction();
                 
                private:
                    Ui::MenuDaftar *ui;
                

                };
                #endif // MENUDAFTAR_H
                @

                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