Unsolved C++ - Can't access function in another class
-
Might be a silly question but did you implement your class constructor ?
-
@SGaist
A silly answer, I don't know about class constructors in this context. -
@mad-hatter said in C++ - Can't access function in another class:
I don't know about class constructors in this context
Then you should learn.
Do you have this in your cpp file:QG_CommandEdit::QG_CommandEdit(QWidget* parent=0) { }
-
Hello,
Thanks for your response.
I can't change this file as its part of an open source project.@jsulm
This is in the qg_commandedit.cpp file.QG_CommandEdit::QG_CommandEdit(QWidget* parent) : QLineEdit(parent) , keycode_mode(false) , relative_ray("none") , calculator_mode(false) { setStyleSheet("selection-color: white; selection-background-color: green;"); setFrame(false); setFocusPolicy(Qt::StrongFocus); }
Regards
-
Show the .pro or .pri file where the source "qg_commandedit.cpp" is included.
-
Pro file
TEMPLATE = app DISABLE_POSTSCRIPT = false #uncomment to enable a Debugging menu entry for basic unit testing #DEFINES += LC_DEBUGGING DEFINES += DWGSUPPORT DEFINES -= JWW_WRITE_SUPPORT LC_VERSION="2.2.0-alpha" VERSION=$${LC_VERSION} # Store intermedia stuff somewhere else GENERATED_DIR = ../../generated/librecad # Use common project definitions. include(../../common.pri) include(./boost.pri) include(./muparser.pri) CONFIG += qt \ warn_on \ link_prl \ verbose \ depend_includepath QT += widgets printsupport CONFIG += c++11 *-g++ { QMAKE_CXXFLAGS += -fext-numeric-literals } GEN_LIB_DIR = ../../generated/lib PRE_TARGETDEPS += $$GEN_LIB_DIR/libdxfrw.a \ $$GEN_LIB_DIR/libjwwlib.a DESTDIR = $${INSTALLDIR} # Make translations at the end of the process unix { LC_VERSION=$$system([ "$(which git)x" != "x" -a -d ../../.git ] && echo "$(git describe --tags)" || echo "$${LC_VERSION}") macx { TARGET = LibreCAD VERSION=$$system(echo "$${LC_VERSION}" | sed -e 's/\-.*//g') QMAKE_INFO_PLIST = Info.plist.app DEFINES += QC_APPDIR="\"LibreCAD\"" ICON = ../res/main/librecad.icns contains(DISABLE_POSTSCRIPT, false) { QMAKE_POST_LINK = /bin/sh $$_PRO_FILE_PWD_/../../scripts/postprocess-osx.sh $$OUT_PWD/$${DESTDIR}/$${TARGET}.app/ $$[QT_INSTALL_BINS]; QMAKE_POST_LINK += /usr/libexec/PlistBuddy -c \"Set :CFBundleGetInfoString string $${TARGET} $${LC_VERSION}\" $$OUT_PWD/$${DESTDIR}/$${TARGET}.app/Contents/Info.plist; } } else { TARGET = librecad DEFINES += QC_APPDIR="\"librecad\"" RC_FILE = ../res/main/librecad.icns contains(DISABLE_POSTSCRIPT, false) { QMAKE_POST_LINK = cd $$_PRO_FILE_PWD_/../.. && scripts/postprocess-unix.sh } } } win32 { TARGET = LibreCAD DEFINES += QC_APPDIR="\"LibreCAD\"" # add MSYSGIT_DIR = PathToGitBinFolder (without quotes) in custom.pro file, for commit hash in about dialog !isEmpty( MSYSGIT_DIR ) { LC_VERSION = $$system( \"$$MSYSGIT_DIR/git.exe\" describe --tags || echo "$${LC_VERSION}") } RC_FILE = ../res/main/librecad.rc contains(DISABLE_POSTSCRIPT, false) { QMAKE_POST_LINK = "$$_PRO_FILE_PWD_/../../scripts/postprocess-win.bat" $$LC_VERSION } } DEFINES += LC_VERSION=\"$$LC_VERSION\" # Additional libraries to load LIBS += -L../../generated/lib \ -ldxfrw \ -ljwwlib INCLUDEPATH += \ HEADERS += ui/lc_actionfactory.h \ .... ui/qg_commandedit.h \ ... SOURCES += ui/lc_actionfactory.cpp \ ... ui/qg_commandedit.cpp \ ...
-
@mad-hatter said in C++ - Can't access function in another class:
INCLUDEPATH +=
HEADERS += ui/lc_actionfactory.h \Add a newline between these lines! Or rather, remove the INCLUDEPATH entirely.
-
Thanks for your reply.
I don't want to alter the pro file as it belongs to an open source project that works as it is.Regards
-
It is a bug, at least tell them to fix it if you don't want to do it yourself. If a project is open source, by the way, you do have all the rights to do that modification on your own.
-
Hello,
INCLUDEPATH +=
HEADERS += ui/lc_actionfactory.h \I'm sorry, ' INCLUDEPATH += ' should not be there, its a copy and paste error on my part.
Regards
-
Hello,
I've changed the code and I am left with one error now.
Is there something I should add in the header file?
Help please!Regards
QG_CommandEdit *inst = nullptr; inst->QG_CommandEdit::readCommandFile( where ); //line 248 error: undefined reference to `QG_CommandEdit::readCommandFile(QString const&)' // line 248
-
Hi @mad-hatter
Is there something I should add in the header file?
That would help to resolve compile errors, when the compiler cannot find the definition of a function.
Linker errors mean, the linker cannot find the implementation of the function.
Usually this means either the implementation is missing in your source file or you have it in a source file that is not compiled/linked.
Regards