Important: Please read the Qt Code of Conduct -

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;


  • Lifetime Qt Champion

    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

  • Lifetime Qt Champion


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

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

  • Lifetime Qt Champion

    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

  • Lifetime Qt Champion

    if inside .cpp
    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.

  • Lifetime Qt Champion

    @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
        coreedit(QString fPath, QWidget *parent = 0);
        QString workFilePath() const {
            return filePath;}
        void lineNumberAreaPaintEvent(QPaintEvent *event);
        int lineNumberAreaWidth();
        QWidget* lineNumberArea_() const {
            return lineNumberArea;}
        void resizeEvent(QResizeEvent *event) override;
    private slots:
        void updateLineNumberAreaWidth(int newBlockCount);
        void highlightCurrentLine();
        void updateLineNumberArea(const QRect &, int);
        QString filePath;
        QWidget *lineNumberArea;
    class LineNumberArea : public QWidget
        LineNumberArea(coreedit *editor) : QWidget(editor) {
            coreedit_ = editor;}
        QSize sizeHint() const override {
            return QSize(coreedit_->lineNumberAreaWidth(), 0);}
        void paintEvent(QPaintEvent *event) override {
        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
        explicit corepad(QWidget *parent = 0);
        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();
        void closeEvent(QCloseEvent *event);
        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

  • Lifetime Qt Champion

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

  • Lifetime Qt Champion

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

  • Lifetime Qt Champion

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

Log in to reply