Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++ - Can't access function in another class
Forum Updated to NodeBB v4.3 + New Features

C++ - Can't access function in another class

Scheduled Pinned Locked Moved Unsolved C++ Gurus
18 Posts 6 Posters 4.0k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #7

    Might be a silly question but did you implement your class constructor ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • M Offline
      M Offline
      mad-hatter
      wrote on last edited by
      #8

      @SGaist
      A silly answer, I don't know about class constructors in this context.

      jsulmJ 1 Reply Last reply
      0
      • M mad-hatter

        @SGaist
        A silly answer, I don't know about class constructors in this context.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @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)
        {
        }
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • M Offline
          M Offline
          mad-hatter
          wrote on last edited by
          #10

          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

          K 1 Reply Last reply
          0
          • M mad-hatter

            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

            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #11

            @mad-hatter

            Show the .pro or .pri file where the source "qg_commandedit.cpp" is included.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mad-hatter
              wrote on last edited by
              #12

              @koahnig

              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 \
                  ...
              
              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #13

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

                (Z(:^

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  mad-hatter
                  wrote on last edited by
                  #14

                  @sierdzio

                  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

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #15

                    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.

                    (Z(:^

                    1 Reply Last reply
                    4
                    • M Offline
                      M Offline
                      mad-hatter
                      wrote on last edited by
                      #16

                      Hello,

                      @sierdzio

                      INCLUDEPATH +=
                      HEADERS += ui/lc_actionfactory.h \

                      I'm sorry, ' INCLUDEPATH += ' should not be there, its a copy and paste error on my part.

                      Regards

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mad-hatter
                        wrote on last edited by
                        #17

                        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
                        
                        aha_1980A 1 Reply Last reply
                        0
                        • M mad-hatter

                          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
                          
                          aha_1980A Offline
                          aha_1980A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on last edited by aha_1980
                          #18

                          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

                          Qt has to stay free or it will die.

                          1 Reply Last reply
                          3

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved