not finding class



  • i included the header file .but it is telling me it can't find the class

    /home/shaber/Desktop/Folder/work3/coreApps/app/corepad/corepad.h:85: error: ‘coreedit’ does not name a type; did you mean ‘corepad’?
         coreedit *text;
         ^~~~~~~~
         corepad
    

    0_1534146349521_Screenshot_2018-08-13_13-44-06.png


  • Qt Champions 2017

    Hi
    if you are VERY sure, that
    you spelled classname right and have the right include file, the right place.
    Then maybe you included corepad in corededit and reverse ?



  • @mrjj
    i am pretty sure of spelling and include .
    when i do ctrl + mouseclike on the include and the declaration ,it drictly goes to the coreedit.h


  • Qt Champions 2017

    @saber

    ok make sure its not a circular reference then.
    also, clean build folder completely and rerun qmake and
    see.



  • @mrjj
    i am clean building it.
    and what is circular reference?can you see the picture and see if i did?


  • Qt Champions 2017

    @saber
    hi
    it means file1 include file2 and file2 includes file1 ( in .h)



  • @mrjj
    clean buil not worked and i did not circular reference.

    update : i think reference is hepping through another cpp file. that cpp used by both


  • Qt Champions 2017

    @saber
    if inside .cpp
    like
    include A.h
    include B.h
    then its pretty normal.
    and its not that.

    Try a clean file.
    and try use the class i dont know and see if same thing happens.


  • Moderators

    @saber Can you show coreedit.h and corepad.h? But please not as screen-shot!
    Is coreedit in a namespace?



  • @jsulm

    
    #ifndef COREEDIT_H
    #define COREEDIT_H
    
    #include "chighlighter.h"
    
    #include <QDebug>
    #include <QPlainTextEdit>
    #include <QPainter>
    #include <QTextBlock>
    
    //#include "utilities/utilities.h"
    
    
    class coreedit : public QPlainTextEdit
    {
        Q_OBJECT
    
    public:
        coreedit(QString fPath, QWidget *parent = 0);
    
        QString workFilePath() const {
            return filePath;}
    
        void lineNumberAreaPaintEvent(QPaintEvent *event);
        int lineNumberAreaWidth();
    
        QWidget* lineNumberArea_() const {
            return lineNumberArea;}
    
    protected:
        void resizeEvent(QResizeEvent *event) override;
    
    private slots:
        void updateLineNumberAreaWidth(int newBlockCount);
        void highlightCurrentLine();
        void updateLineNumberArea(const QRect &, int);
    
    private:
        QString filePath;
        QWidget *lineNumberArea;
    
    };
    
    
    class LineNumberArea : public QWidget
    {
    public:
        LineNumberArea(coreedit *editor) : QWidget(editor) {
            coreedit_ = editor;}
    
        QSize sizeHint() const override {
            return QSize(coreedit_->lineNumberAreaWidth(), 0);}
    
    protected:
        void paintEvent(QPaintEvent *event) override {
            coreedit_->lineNumberAreaPaintEvent(event);}
    
    private:
        coreedit *coreedit_;
    
    };
    
    #endif // COREEDIT_H
    
    
    
    #ifndef COREPAD_H
    #define COREPAD_H
    
    #include <QFile>
    #include <QFileDialog>
    #include <QShortcut>
    #include <QFileInfo>
    #include <QDate>
    #include <QDateTime>
    #include <QMessageBox>
    #include <QDebug>
    #include <QWidget>
    #include <QCloseEvent>
    
    #include "utilities/utilities.h"
    #include "bookmarks/bookmarks.h"
    #include "coreedit.h"
    
    
    namespace Ui {
    class corepad;
    }
    
    class corepad : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit corepad(QWidget *parent = 0);
        ~corepad();
    
        QString workFilePath;
        void openText(const QString &filePath);
        bool initializeNewTab(const QString &filePath);
        int tabsCount();
        QString currentFilePath(int index);
    
    private slots:
        void textCopyAvailable(bool b);
        void textUndoAvailable(bool b);
        void textRedoAvailable(bool b);
        void textTextChanged();
        void on_notes_currentChanged(int index);
        void on_notes_tabCloseRequested(int index);
        void on_cOpen_clicked();
        void on_cNew_clicked();
        bool on_cSave_clicked();
        void on_cSaveAs_clicked();
        void on_cCopy_clicked();
        void on_cPaste_clicked();
        void on_cCut_clicked();
        void on_cUndo_clicked();
        void on_cRedo_clicked();
        void on_addDate_clicked();
        void on_bookMarkIt_clicked();
        void on_searchHere_textChanged(const QString &arg1);
        void on_nextW_clicked();
        void on_previousW_clicked();
        void quitClicked();
        void on_fontShow_clicked();
        void on_fontSize_valueChanged(int arg1);
        void on_search_clicked();
    
    protected:
        void closeEvent(QCloseEvent *event);
    
    private:
        Ui::corepad *ui;
        coreedit *text;
        QStringList tabInfo; //Store tab information (Index, IsSaved, IsUpdated, FilePath)
    
        bool started;
        bool saveTo(const QString &filePath);
        void findS(QString searchS, bool reverse, QTextDocument::FindFlags flag = nullptr);
        bool closeTab(int index);
    
        //Accessing information through tab information
        QString isCurrentSaved(int index);
        QString isCurrentUpdated(int index);
    
        //Saving information at tab information
        bool setCurrent(int index, int isSaved, int isUpdated, const QString &filePath);
    
        void shotcuts();
        void reIndex();
    };
    
    #endif // COREPAD_H
    
    

  • Moderators

    @saber Since you're only using a pointer to coreedit it would be enough to have a forward declaration. So, instead of including coreedit.h (remove it) you can do:

    class coreeedit;
    class corepad: ...
    

    And include coreedit.h in corepad.cpp.



  • i first commented the third.cpp from the coreedite.h then it builds fine.
    and reverse the way it dose not build .

    so the circular reference is happing through another cpp file.
    here it is #include "utilities/utilities.h" ,see it is included in both header file.

    what can i do?


  • Moderators

    @saber Get rid of circular dependency. How? Read my post above about forward declarations. And think about your design: does a utility class really need to know about coreedit?



  • @jsulm
    i can confirm that the cause is circular dependency.
    i restructured my cpp files and function .sperated the function that used by every cpp file .
    now it fixed.
    sorry i did not understand the forward declaration.but i will try to understand .


  • Moderators

    @saber Forward declaration is just a declaration of a class without definition (without class body):

    class coreeedit; // This is forward declaration
    class corepad: ...
    

    Farward declaration in this case tells the compiler that coreedit is a class, this is already enough information for compiler to declare pointers to coreedit. But in cpp you need to include the header file with coreedit definition, so compiler knows more about it to be able to access its variables and methods.



  • @jsulm ohh .understand .
    i saw those in many cpp files.i understand now those.
    thanks


Log in to reply
 

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