Results 1 to 5 of 5

Thread: Strange compile error in subclass

  1. #1
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Strange compile error in subclass

    Hi, I'm using eclipse integration 1.6.1 and Qt 1.6.2. I'm having a problem creating a simple non-Qt class structure. I've created a folder called "math" and I have these files in it:

    DElement.h
    Qt Code:
    1. /**
    2.  * DElement.h
    3.  *
    4.  * Created on: Feb 27, 2010
    5.  * Author: Eric
    6.  *
    7.  * A generic abstract class for an "element" which can be used in a stack. So it can be a number or an equation.
    8.  * Subclasses need to be able to supply a string representation and be able to parse from a string.
    9.  */
    10.  
    11. #ifndef DELEMENT_H_
    12. #define DELEMENT_H_
    13. #include <QtCore/QString>
    14.  
    15. class DElement {
    16. public:
    17. virtual QString toString() = 0;
    18. virtual void fromString(const QString &string) = 0;
    19.  
    20. DElement();
    21. virtual ~DElement();
    22. };
    23.  
    24. #endif /* DELEMENT_H_ */
    To copy to clipboard, switch view to plain text mode 

    DElement.cpp
    Qt Code:
    1. /*
    2.  * DElement.cpp
    3.  *
    4.  * Created on: Feb 27, 2010
    5.  * Author: Eric
    6.  */
    7.  
    8. #include "DElement.h"
    9.  
    10. DElement::DElement() {
    11. // Not much to do here
    12. }
    13.  
    14. DElement::~DElement() {
    15. // TODO Auto-generated destructor stub
    16. }
    To copy to clipboard, switch view to plain text mode 

    DNumber.h
    Qt Code:
    1. /**
    2.  * DNumber.h
    3.  *
    4.  * Created on: Feb 27, 2010
    5.  * Author: Eric
    6.  *
    7.  * DNumber represents a MAPM object which is also a DElement for display purposes.
    8.  */
    9.  
    10. #ifndef DNUMBER_H_
    11. #define DNUMBER_H_
    12.  
    13. #include "DElement.h"
    14. // uses MAPM :)
    15. #include <F:/Programs/mapm/M_APM.H>
    16. #include <QtCore/QString>
    17.  
    18. class DNumber: public DElement, public MAPM {
    19. public:
    20. DNumber(double val);
    21. virtual ~DNumber();
    22. private:
    23.  
    24. };
    25.  
    26. #endif /* DNUMBER_H_ */
    To copy to clipboard, switch view to plain text mode 

    DNumber.cpp
    Qt Code:
    1. /*
    2.  * DNumber.cpp
    3.  *
    4.  * Created on: Feb 27, 2010
    5.  * Author: Eric
    6.  */
    7.  
    8. #include "DNumber.h"
    9.  
    10. DNumber::DNumber(double val) {
    11. // TODO Auto-generated constructor stub
    12. }
    13.  
    14. DNumber::~DNumber() {
    15. // TODO Auto-generated destructor stub
    16. }
    To copy to clipboard, switch view to plain text mode 

    And the following error is produced:
    Qt Code:
    1. mingw32-make debug
    2. mingw32-make -f Makefile.Debug
    3. mingw32-make[1]: Entering directory `G:/Documents/Projects/Demurr'
    4. g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"f:\Programs\Qt4.6\qt\include\QtCore" -I"f:\Programs\Qt4.6\qt\include\QtGui" -I"f:\Programs\Qt4.6\qt\include\QtOpenGL" -I"f:\Programs\Qt4.6\qt\include" -I"f:\Programs\Qt4.6\qt\include\ActiveQt" -I"debug" -I"." -I"f:\Programs\Qt4.6\qt\mkspecs\win32-g++" -o debug\DNumber.o math\DNumber.cpp
    5. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\Demurr.exe debug/DNumber.o debug/main.o debug/mainwindow.o debug/stacktabwidget.o debug/tabpage.o debug/stacktablemodel.o debug/moc_mainwindow.o debug/moc_stacktabwidget.o debug/moc_tabpage.o -L"f:\Programs\Qt4.6\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
    6. debug/DNumber.o: In function `DNumber':
    7. G:\Documents\Projects\Demurr/math/DNumber.cpp:10: undefined reference to `DElement::DElement()'
    8. G:\Documents\Projects\Demurr/math/DNumber.cpp:13: undefined reference to `DElement::~DElement()'
    9. G:\Documents\Projects\Demurr/math/DNumber.cpp:10: undefined reference to `DElement::DElement()'
    10. G:\Documents\Projects\Demurr/math/DNumber.cpp:13: undefined reference to `DElement::~DElement()'
    11. debug/DNumber.o: In function `~DNumber':
    12. G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
    13. G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
    14. G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
    15. G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
    16. debug/DNumber.o:G:\Documents\Projects\Demurr/math/DNumber.cpp:17: more undefined references to `DElement::~DElement()' follow
    To copy to clipboard, switch view to plain text mode 

    Which is stupid because
    Qt Code:
    1. class A
    2. {
    3. public:
    4. A();
    5. virtual ~A();
    6. };
    7.  
    8. class B : public A
    9. {
    10. public:
    11. B();
    12. virtual ~B();
    13. };
    14.  
    15. A::A(){}
    16. A::~A(){}
    17. B::B(){}
    18. B::~B(){}
    To copy to clipboard, switch view to plain text mode 
    this compiles fine, even if I split it into separate files. It's not the pure virtuals either, I got rid of = 0 and it still fails. I wish I could spend more time developing and less time trying to fix strange errors that should not be happening. I've been trying to use Qt for some projects of mine for over a year and I finally got a project to compile only yesterday. MAPM is creating more errors but I'd like to clear up this first.
    Last edited by space_otter; 27th February 2010 at 22:19.

  2. #2
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange compile error in subclass

    OK, I think I'm getting a handle on this. For some reason, the Qt .pro file was missing important things like, say, the class it was complaining about being undefined. It was also missing the include directory for MAPM. Adding this information to the pro file seems to have fixed the problem. Why doesn't it do this automatically? I'm not impressed.

  3. #3
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange compile error in subclass

    Ack! I made a new dialog and it set the project file back! What am I doing wrong?

  4. #4
    Join Date
    Jan 2010
    Posts
    73
    Thanks
    6
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange compile error in subclass

    I assume that you are not placing these files in libraries, and are compiling them directly...

    When you add something new, do you re-run qmake so that all of the proper files end up in the makefile? This really messed with me for a while.

  5. #5
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange compile error in subclass

    I don't know if qmake is re-run, I'm using an IDE which re-generates the .pro file incorrectly. I need to include another library, and even though I added it to the eclipse project it deletes it from the pro file. Like I said, I'm not impressed. Anyway, I switched to Qt Creator which has some interface disadvantages but it doesn't mess up the file.

    About the makefile, I'm pretty sure its not the makefile that's the problem. When I move files into different directories & add new classes it of course needs to modify the qt pro file to account for this. What would happen is that when it was done the qt pro file was wrong, it was missing essential files and my library include. When I edited the file myself everything worked.

    I'm doing better now. I wanted to use eclipse because it's a fully fleshed-out IDE. But for the life of me I can't figure out how to set eclipse's compiler. I've looked everywhere, and I need to make sure it's using the right one.
    Last edited by space_otter; 4th March 2010 at 00:47.

Similar Threads

  1. no compile error, but error on run with QMenu QAction
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 12:05
  2. Strange output: Can't compile for WinCE to save my life!
    By codeslicer in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2010, 15:55
  3. Strange Error
    By keeperofthegrove in forum Newbie
    Replies: 4
    Last Post: 22nd October 2008, 15:16
  4. strange QT error out of nowhere
    By Penut in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2008, 02:46
  5. Replies: 9
    Last Post: 29th March 2007, 14:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.