not finding class
-
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 ? -
#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
-
@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?
-
@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 . -
@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.