[Qt-interest] Frequent error - help pls
Patric
userqt at gmail.com
Mon Aug 31 21:56:29 CEST 2009
You can't add the Q_OBJECT macro if your class doesn't inherit from QObject. Also you should use virtual destructor for your abstract class in order for the late binding to work. Is your save method defined and are you sure you want a method who is virtual to be private ?
Also it's a good thing to name your methods with first letter - lower case, in order to easily distinct them from the constructors for example.
----- Original Message -----
From: Spulber Iosif
To: qt-interest at trolltech.com
Sent: Monday, August 31, 2009 9:48 PM
Subject: [Qt-interest] Frequent error - help pls
Ok, so I tried some stuff and I got some things, but anyways here's the code:
~~~~~~~~~~~~~
#ifndef QUESTION_H
#define QUESTION_H
class QuestionData
{
public:
QString QuestionText;
};
class Question
{
public:
enum Type {TrueFalse, SingleChoice};
Type QuestionType;
QuestionData *Data;
void LoadData (Question *Data);
private:
virtual void Save ();
};
class SingleChoiceData: public QuestionData
{
public:
int NumberOfAnswers;
int Correct;
QString Answers[10];
};
class TrueFalseData: public QuestionData
{
public:
bool Correct;
QString Answer1, Answer2;
};
#endif // QUESTION_H
~~~~~~~~~~~~~~
The problem arises when I try to declare any Question object; it says :
D:/Qt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/locale_facets.tcc:2498: undefined reference to `vtable for Question'
The compile output:
Running build steps for project QuizMaker...
Configuration unchanged, skipping QMake step.
Starting: D:/Qt/mingw/bin/mingw32-make.exe -w
mingw32-make: Entering directory `C:/Documents and Settings/TheBlackElf/My Documents/QuizMaker'
D:/Qt/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/TheBlackElf/My Documents/QuizMaker'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"d:\Qt\qt\include\QtCore" -I"d:\Qt\qt\include\QtGui" -I"d:\Qt\qt\include" -I"d:\Qt\qt\include\ActiveQt" -I"debug" -I"d:\Qt\qt\mkspecs\win32-g++" -o debug\main.o main.cpp
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"d:\Qt\qt\include\QtCore" -I"d:\Qt\qt\include\QtGui" -I"d:\Qt\qt\include" -I"d:\Qt\qt\include\ActiveQt" -I"debug" -I"d:\Qt\qt\mkspecs\win32-g++" -o debug\mainwindow.o mainwindow.cpp
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"d:\Qt\qt\include\QtCore" -I"d:\Qt\qt\include\QtGui" -I"d:\Qt\qt\include" -I"d:\Qt\qt\include\ActiveQt" -I"debug" -I"d:\Qt\qt\mkspecs\win32-g++" -o debug\truefalse.o truefalse.cpp
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"d:\Qt\qt\include\QtCore" -I"d:\Qt\qt\include\QtGui" -I"d:\Qt\qt\include" -I"d:\Qt\qt\include\ActiveQt" -I"debug" -I"d:\Qt\qt\mkspecs\win32-g++" -o debug\singlechoice.o singlechoice.cpp
D:/Qt/qt/bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"d:\Qt\qt\include\QtCore" -I"d:\Qt\qt\include\QtGui" -I"d:\Qt\qt\include" -I"d:\Qt\qt\include\ActiveQt" -I"debug" -I"d:\Qt\qt\mkspecs\win32-g++" -D__GNUC__ -DWIN32 mainwindow.h -o debug\moc_mainwindow.cpp
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"d:\Qt\qt\include\QtCore" -I"d:\Qt\qt\include\QtGui" -I"d:\Qt\qt\include" -I"d:\Qt\qt\include\ActiveQt" -I"debug" -I"d:\Qt\qt\mkspecs\win32-g++" -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\QuizMaker.exe debug/main.o debug/mainwindow.o debug/truefalse.o debug/singlechoice.o debug/moc_mainwindow.o -L"d:\Qt\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Documents and Settings/TheBlackElf/My Documents/QuizMaker'
mingw32-make: Leaving directory `C:/Documents and Settings/TheBlackElf/My Documents/QuizMaker'
~~~~~~~ here it gets red:
debug/mainwindow.o: In function `ZSt17__verify_groupingPKcjRKSs':
D:/Qt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/locale_facets.tcc:2498: undefined reference to `vtable for Question'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QuizMaker.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project QuizMaker
When executing build step 'Make'
~~~~~~~~
To explain how it occoured (and I think last time it did the same): I wanted a slot in Question so I inserted Q_OBJECT in the beginning. It didn't recognize Q_OBJECT (btw, what header do I need just for that?). I thought <QApplication> or <QPushButton> should include the macro somehow, but it said that "Q_OBJECT is not inherited through <...>". I then deleted the header inclusion and Q_OBJECT and it produced that error since.
Now I discovered that if I make Save () non-virtual everything is OK. But I really need the virtual function. Also, if I try to declare virtual functions in other classes in the same header it doesn't work as well.
Best regards,
Iosif Spulber
------------------------------------------------------------------------------
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090831/792add82/attachment.html
More information about the Qt-interest-old
mailing list