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



  • 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.



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

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



  • only using namespace UI?



  • 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.



  • 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.



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



  • 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
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.