'CapturarReceta' was not declare in this scope



  • I have this problem when I declare a private pointer to CapturarReceta, also, in the constructor I get "CapturarReceta has not been declared".
    This is my code (.h):
    @
    #ifndef ADVERTENCIA_H
    #define ADVERTENCIA_H

    #include <QDialog>
    #include <QtGlobal>
    #include <capturarreceta.h>
    #include <ListaD.h>
    #include <Receta.h>
    #include <QPointer>
    namespace Ui {
    class Advertencia;
    }

    class Advertencia : public QDialog
    {
    Q_OBJECT

    public:
    explicit Advertencia(ListaD<Receta>* lista,CapturarReceta* paso,qint8 pas,QWidget *parent = 0);
    ~Advertencia();

    private slots:
    void on_Si_clicked();

    void on_No_clicked();
    

    private:
    Ui::Advertencia *ui;
    CapturarReceta *cr;
    ListaD<Receta> *recetas;
    };

    #endif // ADVERTENCIA_H
    @

    I been tried everything and nothing works.



  • Hi, can you post your capturarreceta.h? maybe you've used a namespace or something.



  • Hi Xander, this is the code from capturareceta.h:

    @
    #ifndef CAPTURARRECETA_H
    #define CAPTURARRECETA_H

    #include <QWidget>
    #include <QtGlobal>
    #include <advertencia.h>
    #include <menurecetario.h>
    #include "Recetario.h"
    #include "ListaD.h"
    #include "Receta.h"

    namespace Ui {
    class CapturarReceta;
    }

    class CapturarReceta : public QWidget
    {
    Q_OBJECT

    public:
    explicit CapturarReceta(ListaD<Receta>* pos,QWidget *parent = 0);
    ~CapturarReceta();

    private slots:
    void on_Regresar_clicked();

    private:
    Ui::CapturarReceta *ui;
    ListaD<Receta> *recetas;
    };

    #endif // CAPTURARRECETA_H
    @

    I tried declare "Ui::CapturarReceta *cr;" but gives me the same error.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you show the Advertencia implementation ?

    Also the complete error could be useful



  • Oh I just noticed, you should use
    @
    #include "capturarreceta.h"
    @
    for local files, instead of
    @
    #include <capturarreceta.h>
    @
    yeah there is a difference. :D

    About the Ui namespace, actually CapturarReceta is your "main" class and Ui::CapturarReceta the UI class (generated from the CapturarReceta.ui file), so that is not the same class.

    If you still have a compile error post the exact error message please (with line number etc).



  • Hi!, and thanks.

    This is the code from Advertencia.cpp

    @
    #include "advertencia.h"
    #include "ui_advertencia.h"
    #include <QtGlobal>
    Advertencia::Advertencia(ListaD<Receta> *lista,CapturarReceta *paso, qint8 pas,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Advertencia)
    {
    ui->setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose,true);
    cr=paso;
    recetas=lista;
    if(pas==1)ui->Mensaje->setText("¿Seguro que deseas regresar al menú anterior?");
    }

    Advertencia::~Advertencia()
    {
    delete ui;
    }

    void Advertencia::on_Si_clicked()
    {
    cr->close();
    MenuRecetario *menu = new MenuRecetario(recetas);
    menu->show();
    close();
    }

    void Advertencia::on_No_clicked()
    {
    close();
    }
    @

    And the complete error:

    bq. C:\Users\Servidor-PC\Desktop\Recetario\capturarreceta.h:6: In file included from ......\Servidor-PC\Desktop\Recetario/capturarreceta.h:6:0,
    C:\Users\Servidor-PC\Desktop\Recetario\menurecetario.h:7: from ......\Servidor-PC\Desktop\Recetario/menurecetario.h:7,
    C:\Users\Servidor-PC\Desktop\Recetario\main.cpp:1: from ......\Servidor-PC\Desktop\Recetario\main.cpp:1:
    C:\Users\Servidor-PC\Desktop\Recetario\advertencia.h:21: error: 'CapturarReceta' has not been declared
    explicit Advertencia(ListaD<Receta>* lista,CapturarReceta* paso,qint8 pas,QWidget *parent = 0);
    ^
    C:\Users\Servidor-PC\Desktop\Recetario\advertencia.h:31: error: 'CapturarReceta' does not name a type
    CapturarReceta *cr;
    ^

    Thanks in advance.



  • [quote author="Xander84" date="1397504057"]Oh I just noticed, you should use
    @
    #include "capturarreceta.h"
    @
    for local files, instead of
    @
    #include <capturarreceta.h>
    @
    yeah there is a difference. :D

    About the Ui namespace, actually CapturarReceta is your "main" class and Ui::CapturarReceta the UI class (generated from the CapturarReceta.ui file), so that is not the same class.

    If you still have a compile error post the exact error message please (with line number etc).[/quote]

    I tried this before, and the error still be the same.



  • You should always try to fix the first error, which is "error: ‘CapturarReceta’ has not been declared explicit", the error after that is just a result of the first error in most cases.
    As far as I can see you should remove the explicit keyword here:;
    @
    explicit Advertencia(ListaD<Receta>* lista,CapturarReceta* paso,qint8 pas,QWidget *parent = 0);
    @
    Declaring a constructor explicit only makes sense if you have only one non-default parameter I guess.



  • [quote author="Xander84" date="1397505508"]You should always try to fix the first error, which is "error: ‘CapturarReceta’ has not been declared explicit", the error after that is just a result of the first error in most cases.
    As far as I can see you should remove the explicit keyword here:;
    @
    explicit Advertencia(ListaD<Receta>* lista,CapturarReceta* paso,qint8 pas,QWidget *parent = 0);
    @
    Declaring a constructor explicit only makes sense if you have only one non-default parameter I guess.[/quote]

    I try deleted "explicit" in all the headers (I did not know what it means explicit). And the error still the same.



  • Ok then I have no idea, maybe it's some weird build error did you try and delete all build folders with the temporary files? With c++ the incremental compiler is sometimes corrupting the files, don't ask me but sometimes a full clean does the trick.. :D

    If you need a simple explanation what explicit does: http://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-in-c-mean
    e.g.
    @
    QString str = "foo"; // implicit
    @
    that does an implicit conversion from char* to QString (calling the QString(char*) constructor), if you declare the constructor with explicit you can't do that and have so explicitly call it, in this case:
    @
    QString str = QString("foo"); // explicit
    @



  • [quote author="Xander84" date="1397506445"]Ok then I have no idea, maybe it's some weird build error did you try and delete all build folders with the temporary files? With c++ the incremental compiler is sometimes corrupting the files, don't ask me but sometimes a full clean does the trick.. :D

    [/quote]

    I tried in 3 different PC´s, Linux and Windows, and the error still there. With every object I declare on this class, throw the same error.



  • If it is possible for you do share the source code or at least the class and all dependencies I could try it to compile it myself, problem with some errors like this is like fishing in the dark, you can try some things that is not easily done over the forums I guess.. maybe someone else has an idea but I don't see any syntax errors from here.


Log in to reply
 

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