Qt-interest Archive, November 2004
udefined reference to vtable, how get rid of?
Message 1 in thread
I am trying to learn how to use Qt after years of using xforms for X
apps. I went through the cannonball game tutorials and then started
playing on my own, especially with QTextEdit. I overrode ::append to do
some testing and that was ok. But, when I tried to add a new slot the
trouble began.
First I didn't put Q_OBJECT in the class declaration and got a runtime
message saying the connect failed. Ok, then I added Q_OBJECT and got the
"undefined reference to 'vtable for mtTextEdit' error.
I removed Makefile and the .pro file and reran
qmake -project
qmake
before building. Which, according to my research on other posts, should
take care of the meta code compiling.
Here is my test code:
#include <qapplication.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qfont.h>
#include <qvbox.h>
class myTextEdit : public QTextEdit
{
Q_OBJECT
public:
myTextEdit(QWidget *parent=0, const char *name=0);
int count;
public slots:
void append(QString line);
void putLine(void);
};
myTextEdit::myTextEdit(QWidget *parent, const char *name)
: QTextEdit(parent, name)
{
count = 0;
}
void myTextEdit::append(QString line)
{
count++;
if(count > 50){
removeParagraph(0);
count = 50;
}
QTextEdit::append(line);
}
void myTextEdit::putLine(void)
{
count++;
if(count > 50){
removeParagraph(0);
count = 50;
}
QTextEdit::append("This is a line");
}
int main(int argc, char *argv[]){
QString line;
QApplication a(argc, argv);
QVBox box;
box.resize( 200, 120 );
myTextEdit *w = new myTextEdit(&box, "edit");
QPushButton *button = new QPushButton("Line", &box, "line");
QObject::connect(button, SIGNAL(clicked(void)), w, SLOT(putLine(void)));
box.setGeometry(100, 100, 200, 120);
a.setMainWidget(&box);
box.show();
for(int i=0;i<100;i++){
line = QString("This is line %1")
.arg(i);
w->append(line);
}
return a.exec();
}
What I am trying to do is I want a widget that displays lines of data as
they come in, but only the last fifty lines. The putLine() slot was a
test to see the behavoir of the QTextEdit widget when you delete the
first paragraph, and then append a new one.
But, no luck on building.
Thanks,
tj
Message 2 in thread
Without even addressing the vtable issue, note that you can put a QTextEdit
in LogText mode, and call setMaxLogLines(), so that you don't need to make
your own class. I'll leave the vtable error for somebody else. :)
Nathan
On 11/10/04 2:21 PM, "owner-qt-interest@xxxxxxxxxxxxx"
<owner-qt-interest@xxxxxxxxxxxxx> wrote:
> I am trying to learn how to use Qt after years of using xforms for X
> apps. I went through the cannonball game tutorials and then started
> playing on my own, especially with QTextEdit. I overrode ::append to do
> some testing and that was ok. But, when I tried to add a new slot the
> trouble began.
> First I didn't put Q_OBJECT in the class declaration and got a runtime
> message saying the connect failed. Ok, then I added Q_OBJECT and got the
> "undefined reference to 'vtable for mtTextEdit' error.
>
> I removed Makefile and the .pro file and reran
> qmake -project
> qmake
> before building. Which, according to my research on other posts, should
> take care of the meta code compiling.
>
> Here is my test code:
> #include <qapplication.h>
> #include <qpushbutton.h>
> #include <qtextedit.h>
> #include <qfont.h>
> #include <qvbox.h>
>
> class myTextEdit : public QTextEdit
> {
> Q_OBJECT
> public:
> myTextEdit(QWidget *parent=0, const char *name=0);
> int count;
>
> public slots:
> void append(QString line);
> void putLine(void);
>
> };
>
> myTextEdit::myTextEdit(QWidget *parent, const char *name)
> : QTextEdit(parent, name)
> {
> count = 0;
> }
>
> void myTextEdit::append(QString line)
> {
> count++;
> if(count > 50){
> removeParagraph(0);
> count = 50;
> }
>
> QTextEdit::append(line);
> }
>
> void myTextEdit::putLine(void)
> {
> count++;
> if(count > 50){
> removeParagraph(0);
> count = 50;
> }
>
> QTextEdit::append("This is a line");
> }
>
> int main(int argc, char *argv[]){
> QString line;
>
> QApplication a(argc, argv);
>
> QVBox box;
> box.resize( 200, 120 );
>
> myTextEdit *w = new myTextEdit(&box, "edit");
> QPushButton *button = new QPushButton("Line", &box, "line");
>
>
> QObject::connect(button, SIGNAL(clicked(void)), w, SLOT(putLine(void)));
>
> box.setGeometry(100, 100, 200, 120);
> a.setMainWidget(&box);
> box.show();
>
>
> for(int i=0;i<100;i++){
> line = QString("This is line %1")
> .arg(i);
> w->append(line);
> }
>
> return a.exec();
>
> }
>
> What I am trying to do is I want a widget that displays lines of data as
> they come in, but only the last fifty lines. The putLine() slot was a
> test to see the behavoir of the QTextEdit widget when you delete the
> first paragraph, and then append a new one.
> But, no luck on building.
>
> Thanks,
> tj
>
> --
> List archive and information: http://lists.trolltech.com/qt-interest/
Message 3 in thread
On November 10, 2004 12:21 pm, tj wrote:
> I am trying to learn how to use Qt after years of using xforms for X
> apps. I went through the cannonball game tutorials and then started
> playing on my own, especially with QTextEdit. I overrode ::append to do
> some testing and that was ok. But, when I tried to add a new slot the
> trouble began.
> First I didn't put Q_OBJECT in the class declaration and got a runtime
> message saying the connect failed. Ok, then I added Q_OBJECT and got the
> "undefined reference to 'vtable for mtTextEdit' error.
>
> I removed Makefile and the .pro file and reran
> qmake -project
> qmake
> before building. Which, according to my research on other posts, should
> take care of the meta code compiling.
Are you SURE that you did this AFTER adding the Q_OBJECT reference? Try
deleting the existing Makefiles, then redoing it.
If that doesn't work, make sure it is creating and linking the moc file for
myTextEdit.
--
[ signature omitted ]
Message 4 in thread
Chris Thompson wrote:
>On November 10, 2004 12:21 pm, tj wrote:
>
>
>>I am trying to learn how to use Qt after years of using xforms for X
>>apps. I went through the cannonball game tutorials and then started
>>playing on my own, especially with QTextEdit. I overrode ::append to do
>>some testing and that was ok. But, when I tried to add a new slot the
>>trouble began.
>>First I didn't put Q_OBJECT in the class declaration and got a runtime
>>message saying the connect failed. Ok, then I added Q_OBJECT and got the
>>"undefined reference to 'vtable for mtTextEdit' error.
>>
>>I removed Makefile and the .pro file and reran
>>qmake -project
>>qmake
>>before building. Which, according to my research on other posts, should
>>take care of the meta code compiling.
>>
>>
>
>Are you SURE that you did this AFTER adding the Q_OBJECT reference? Try
>deleting the existing Makefiles, then redoing it.
>
>If that doesn't work, make sure it is creating and linking the moc file for
>myTextEdit.
>
>
>
Here is what happens starting with only main.cpp.
>qmake -project
directory now contains
main.cpp test1.pro
>qmake
directory now contains
Makefile main.cpp test1.pro
>make
<undefined reference to vtable errors>
directory now contains
Makefile main.cpp main.o test1.pro
No moc files, which is teh reason for the problems, but why no moc files?
tj
Message 5 in thread
I assume you have only one source file, say 'main.cpp'.
When you define signals or slots without having a header file, AFAIK you
have to do two steps manually, as they are:
1. Call the 'moc' manually:
moc main.cpp > moc_main.cpp
2. Include the 'moc_main.cpp' at the end of your 'main.cpp':
#include "moc_main.cpp"
To avoid these steps, always use header files when using signals/slots.
Hope this helps,
Paul
tj wrote:
> I am trying to learn how to use Qt after years of using xforms for X
> apps. I went through the cannonball game tutorials and then started
> playing on my own, especially with QTextEdit. I overrode ::append to do
> some testing and that was ok. But, when I tried to add a new slot the
> trouble began.
> First I didn't put Q_OBJECT in the class declaration and got a runtime
> message saying the connect failed. Ok, then I added Q_OBJECT and got the
> "undefined reference to 'vtable for mtTextEdit' error.
>
> I removed Makefile and the .pro file and reran
> qmake -project
> qmake
> before building. Which, according to my research on other posts, should
> take care of the meta code compiling.
>
> Here is my test code:
> #include <qapplication.h>
> #include <qpushbutton.h>
> #include <qtextedit.h>
> #include <qfont.h>
> #include <qvbox.h>
>
> class myTextEdit : public QTextEdit
> {
> Q_OBJECT
> public:
> myTextEdit(QWidget *parent=0, const char *name=0);
> int count;
>
> public slots:
> void append(QString line);
> void putLine(void);
>
> };
>
> myTextEdit::myTextEdit(QWidget *parent, const char *name)
> : QTextEdit(parent, name)
> {
> count = 0;
> }
>
> void myTextEdit::append(QString line)
> {
> count++;
> if(count > 50){
> removeParagraph(0);
> count = 50;
> }
>
> QTextEdit::append(line);
> }
>
> void myTextEdit::putLine(void)
> {
> count++;
> if(count > 50){
> removeParagraph(0);
> count = 50;
> }
>
> QTextEdit::append("This is a line");
> }
>
> int main(int argc, char *argv[]){
> QString line;
>
> QApplication a(argc, argv);
>
> QVBox box;
> box.resize( 200, 120 );
>
> myTextEdit *w = new myTextEdit(&box, "edit");
> QPushButton *button = new QPushButton("Line", &box, "line");
>
>
> QObject::connect(button, SIGNAL(clicked(void)), w, SLOT(putLine(void)));
>
> box.setGeometry(100, 100, 200, 120);
> a.setMainWidget(&box);
> box.show();
>
>
> for(int i=0;i<100;i++){
> line = QString("This is line %1")
> .arg(i);
> w->append(line);
> }
>
> return a.exec();
>
> }
>
> What I am trying to do is I want a widget that displays lines of data as
> they come in, but only the last fifty lines. The putLine() slot was a
> test to see the behavoir of the QTextEdit widget when you delete the
> first paragraph, and then append a new one.
> But, no luck on building.
>
> Thanks,
> tj
>
> --
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 6 in thread
Paul Ruetz wrote:
> I assume you have only one source file, say 'main.cpp'.
>
> When you define signals or slots without having a header file, AFAIK
> you have to do two steps manually, as they are:
>
> 1. Call the 'moc' manually:
> moc main.cpp > moc_main.cpp
>
> 2. Include the 'moc_main.cpp' at the end of your 'main.cpp':
> #include "moc_main.cpp"
>
> To avoid these steps, always use header files when using signals/slots.
>
> Hope this helps,
>
> Paul
>
>
> tj wrote:
>
>> I am trying to learn how to use Qt after years of using xforms for X
>> apps. I went through the cannonball game tutorials and then started
>> playing on my own, especially with QTextEdit. I overrode ::append to
>> do some testing and that was ok. But, when I tried to add a new slot
>> the trouble began.
>> First I didn't put Q_OBJECT in the class declaration and got a
>> runtime message saying the connect failed. Ok, then I added Q_OBJECT
>> and got the "undefined reference to 'vtable for mtTextEdit' error.
>>
>> I removed Makefile and the .pro file and reran
>> qmake -project
>> qmake
>> before building. Which, according to my research on other posts,
>> should take care of the meta code compiling.
>>
>> Here is my test code:
>> #include <qapplication.h>
>> #include <qpushbutton.h>
>> #include <qtextedit.h>
>> #include <qfont.h>
>> #include <qvbox.h>
>>
>> class myTextEdit : public QTextEdit
>> {
>> Q_OBJECT
>> public:
>> myTextEdit(QWidget *parent=0, const char *name=0);
>> int count;
>>
>> public slots:
>> void append(QString line);
>> void putLine(void);
>>
>> };
>>
>> myTextEdit::myTextEdit(QWidget *parent, const char *name)
>> : QTextEdit(parent, name)
>> {
>> count = 0;
>> }
>>
>> void myTextEdit::append(QString line)
>> {
>> count++;
>> if(count > 50){
>> removeParagraph(0);
>> count = 50;
>> }
>>
>> QTextEdit::append(line);
>> }
>>
>> void myTextEdit::putLine(void)
>> {
>> count++;
>> if(count > 50){
>> removeParagraph(0);
>> count = 50;
>> }
>>
>> QTextEdit::append("This is a line");
>> }
>>
>> int main(int argc, char *argv[]){
>> QString line;
>>
>> QApplication a(argc, argv);
>>
>> QVBox box;
>> box.resize( 200, 120 );
>>
>> myTextEdit *w = new myTextEdit(&box, "edit");
>> QPushButton *button = new QPushButton("Line", &box, "line");
>>
>>
>> QObject::connect(button, SIGNAL(clicked(void)), w,
>> SLOT(putLine(void)));
>>
>> box.setGeometry(100, 100, 200, 120);
>> a.setMainWidget(&box);
>> box.show();
>>
>>
>> for(int i=0;i<100;i++){
>> line = QString("This is line %1")
>> .arg(i);
>> w->append(line);
>> }
>>
>> return a.exec();
>>
>> }
>>
>> What I am trying to do is I want a widget that displays lines of data
>> as they come in, but only the last fifty lines. The putLine() slot
>> was a test to see the behavoir of the QTextEdit widget when you
>> delete the first paragraph, and then append a new one.
>> But, no luck on building.
>>
>> Thanks,
>> tj
>>
>> --
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>
> --
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
moc will only create the moc files if the class is defined in the .h
file it doesn't check the cpp files. To have qmake properly do its thing
break up the files to myTextEdit.h myTextEdit.cpp and main.cpp. This
will give you the results you want.
Tom
--
[ signature omitted ]
Message 7 in thread
Hi,
I rearranged Paul's files:
Put class declaration in an ".h" file
Added destructor (unnecessary? )
Added Q_OBJECT in the private section.
run qmake -projects
qmake
make
And now it seems to work.
I enclose the files.
Best regards
Erik
Wednesday 10 November 2004 21.52 skrev Tom Bradley:
> Paul Ruetz wrote:
> > I assume you have only one source file, say 'main.cpp'.
> >
> > When you define signals or slots without having a header file, AFAIK
> > you have to do two steps manually, as they are:
> >
> > 1. Call the 'moc' manually:
> > moc main.cpp > moc_main.cpp
> >
> > 2. Include the 'moc_main.cpp' at the end of your 'main.cpp':
> > #include "moc_main.cpp"
> >
> > To avoid these steps, always use header files when using signals/slots.
> >
> > Hope this helps,
> >
> > Paul
> >
> > tj wrote:
> >> I am trying to learn how to use Qt after years of using xforms for X
> >> apps. I went through the cannonball game tutorials and then started
> >> playing on my own, especially with QTextEdit. I overrode ::append to
> >> do some testing and that was ok. But, when I tried to add a new slot
> >> the trouble began.
> >> First I didn't put Q_OBJECT in the class declaration and got a
> >> runtime message saying the connect failed. Ok, then I added Q_OBJECT
> >> and got the "undefined reference to 'vtable for mtTextEdit' error.
> >>
> >> I removed Makefile and the .pro file and reran
> >> qmake -project
> >> qmake
> >> before building. Which, according to my research on other posts,
> >> should take care of the meta code compiling.
> >>
> >> Here is my test code:
> >> #include <qapplication.h>
> >> #include <qpushbutton.h>
> >> #include <qtextedit.h>
> >> #include <qfont.h>
> >> #include <qvbox.h>
> >>
> >> class myTextEdit : public QTextEdit
> >> {
> >> Q_OBJECT
> >> public:
> >> myTextEdit(QWidget *parent=0, const char *name=0);
> >> int count;
> >>
> >> public slots:
> >> void append(QString line);
> >> void putLine(void);
> >>
> >> };
> >>
> >> myTextEdit::myTextEdit(QWidget *parent, const char *name)
> >>
> >> : QTextEdit(parent, name)
> >>
> >> {
> >> count = 0;
> >> }
> >>
> >> void myTextEdit::append(QString line)
> >> {
> >> count++;
> >> if(count > 50){
> >> removeParagraph(0);
> >> count = 50;
> >> }
> >>
> >> QTextEdit::append(line);
> >> }
> >>
> >> void myTextEdit::putLine(void)
> >> {
> >> count++;
> >> if(count > 50){
> >> removeParagraph(0);
> >> count = 50;
> >> }
> >>
> >> QTextEdit::append("This is a line");
> >> }
> >>
> >> int main(int argc, char *argv[]){
> >> QString line;
> >>
> >> QApplication a(argc, argv);
> >>
> >> QVBox box;
> >> box.resize( 200, 120 );
> >>
> >> myTextEdit *w = new myTextEdit(&box, "edit");
> >> QPushButton *button = new QPushButton("Line", &box, "line");
> >>
> >>
> >> QObject::connect(button, SIGNAL(clicked(void)), w,
> >> SLOT(putLine(void)));
> >>
> >> box.setGeometry(100, 100, 200, 120);
> >> a.setMainWidget(&box);
> >> box.show();
> >>
> >>
> >> for(int i=0;i<100;i++){
> >> line = QString("This is line %1")
> >> .arg(i);
> >> w->append(line);
> >> }
> >>
> >> return a.exec();
> >>
> >> }
> >>
> >> What I am trying to do is I want a widget that displays lines of data
> >> as they come in, but only the last fifty lines. The putLine() slot
> >> was a test to see the behavoir of the QTextEdit widget when you
> >> delete the first paragraph, and then append a new one.
> >> But, no luck on building.
> >>
> >> Thanks,
> >> tj
> >>
> >> --
> >> List archive and information: http://lists.trolltech.com/qt-interest/
> >
> > --
> > List archive and information: http://lists.trolltech.com/qt-interest/
>
> moc will only create the moc files if the class is defined in the .h
> file it doesn't check the cpp files. To have qmake properly do its thing
> break up the files to myTextEdit.h myTextEdit.cpp and main.cpp. This
> will give you the results you want.
>
> Tom
--
[ signature omitted ]
#############################################################################
# Makefile for building: aaa
# Generated by qmake (1.07a) (Qt 3.3.1) on: Wed Nov 10 22:18:08 2004
# Project: aaa.pro
# Template: app
# Command: $(QMAKE) -o Makefile aaa.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
LEX = flex
YACC = yacc
CFLAGS = -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT
CXXFLAGS = -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT
LEXFLAGS =
YACCFLAGS= -d
INCPATH = -I/usr/lib/qt3/mkspecs/default -I. -I. -I/usr/include -I$(QTDIR)/include
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS) -L/usr/lib/ -L$(QTDIR)/lib/ -L/usr/X11R6/lib/ -lqt -lXext -lX11 -lm
AR = ar cqs
RANLIB =
MOC = $(QTDIR)/bin/moc
UIC = $(QTDIR)/bin/uic
QMAKE = qmake
TAR = tar -cf
GZIP = gzip -9f
COPY = cp -f
COPY_FILE= $(COPY)
COPY_DIR = $(COPY) -r
INSTALL_FILE= $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = rm -f
SYMLINK = ln -sf
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
HEADERS = main.h
SOURCES = main.cpp
OBJECTS = main.o
FORMS =
UICDECLS =
UICIMPLS =
SRCMOC = moc_main.cpp
OBJMOC = moc_main.o
DIST = aaa.pro
QMAKE_TARGET = aaa
DESTDIR =
TARGET = aaa
first: all
####### Implicit rules
.SUFFIXES: .c .o .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) $(LIBS)
mocables: $(SRCMOC)
uicables: $(UICDECLS) $(UICIMPLS)
$(MOC):
( cd $(QTDIR)/src/moc && $(MAKE) )
Makefile: aaa.pro /usr/lib/qt3/mkspecs/default/qmake.conf /usr/lib/qt3/lib/libqt.prl
$(QMAKE) -o Makefile aaa.pro
qmake:
@$(QMAKE) -o Makefile aaa.pro
dist:
@mkdir -p .tmp/aaa && $(COPY_FILE) --parents $(SOURCES) $(HEADERS) $(FORMS) $(DIST) .tmp/aaa/ && ( cd `dirname .tmp/aaa` && $(TAR) aaa.tar aaa && $(GZIP) aaa.tar ) && $(MOVE) `dirname .tmp/aaa`/aaa.tar.gz . && $(DEL_FILE) -r .tmp/aaa
mocclean:
-$(DEL_FILE) $(OBJMOC)
-$(DEL_FILE) $(SRCMOC)
uiclean:
yaccclean:
lexclean:
clean: mocclean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET) $(TARGET)
FORCE:
####### Compile
main.o: main.cpp main.h
moc_main.o: moc_main.cpp main.h
moc_main.cpp: $(MOC) main.h
$(MOC) main.h -o moc_main.cpp
####### Install
install:
uninstall:
#include <qapplication.h>
#include <qapplication.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qfont.h>
#include <qvbox.h>
#include "main.h"
myTextEdit::myTextEdit(QWidget *parent, const char *name)
: QTextEdit(parent, name)
{
count = 0;
}
void myTextEdit::append(QString line)
{
count++;
if(count > 50){
removeParagraph(0);
count = 50;
}
QTextEdit::append(line);
}
void myTextEdit::putLine(void)
{
count++;
if(count > 50){
removeParagraph(0);
count = 50;
}
QTextEdit::append("This is a line");
}
int main(int argc, char *argv[]){
QString line;
QApplication a(argc, argv);
QVBox box;
box.resize( 200, 120 );
myTextEdit *w = new myTextEdit(&box, "edit");
QPushButton *button = new QPushButton("Line", &box, "line");
QObject::connect(button, SIGNAL(clicked(void)), w, SLOT(putLine(void)));
box.setGeometry(100, 100, 200, 120);
a.setMainWidget(&box);
box.show();
for(int i=0;i<100;i++){
line = QString("This is line %1")
.arg(i);
w->append(line);
}
return a.exec();
}
######################################################################
######################################################################
# Automatically generated by qmake (1.07a) Wed Nov 10 22:17:49 2004
######################################################################
TEMPLATE = app
INCLUDEPATH += .
# Input
HEADERS += main.h
SOURCES += main.cpp
/****************************************************************************
/****************************************************************************
** myTextEdit meta object code from reading C++ file 'main.h'
**
** Created: Wed Nov 10 22:18:08 2004
** by: The Qt MOC ($Id: qt/moc_yacc.cpp 3.3.1 edited Feb 18 14:21 $)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#undef QT_NO_COMPAT
#include "main.h"
#include <qmetaobject.h>
#include <qapplication.h>
#include <private/qucomextra_p.h>
#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
#error "This file was generated using the moc from 3.3.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
const char *myTextEdit::className() const
{
return "myTextEdit";
}
QMetaObject *myTextEdit::metaObj = 0;
static QMetaObjectCleanUp cleanUp_myTextEdit( "myTextEdit", &myTextEdit::staticMetaObject );
#ifndef QT_NO_TRANSLATION
QString myTextEdit::tr( const char *s, const char *c )
{
if ( qApp )
return qApp->translate( "myTextEdit", s, c, QApplication::DefaultCodec );
else
return QString::fromLatin1( s );
}
#ifndef QT_NO_TRANSLATION_UTF8
QString myTextEdit::trUtf8( const char *s, const char *c )
{
if ( qApp )
return qApp->translate( "myTextEdit", s, c, QApplication::UnicodeUTF8 );
else
return QString::fromUtf8( s );
}
#endif // QT_NO_TRANSLATION_UTF8
#endif // QT_NO_TRANSLATION
QMetaObject* myTextEdit::staticMetaObject()
{
if ( metaObj )
return metaObj;
QMetaObject* parentObject = QTextEdit::staticMetaObject();
static const QUParameter param_slot_0[] = {
{ "line", &static_QUType_QString, 0, QUParameter::In }
};
static const QUMethod slot_0 = {"append", 1, param_slot_0 };
static const QUMethod slot_1 = {"putLine", 0, 0 };
static const QMetaData slot_tbl[] = {
{ "append(QString)", &slot_0, QMetaData::Public },
{ "putLine()", &slot_1, QMetaData::Public }
};
metaObj = QMetaObject::new_metaobject(
"myTextEdit", parentObject,
slot_tbl, 2,
0, 0,
#ifndef QT_NO_PROPERTIES
0, 0,
0, 0,
#endif // QT_NO_PROPERTIES
0, 0 );
cleanUp_myTextEdit.setMetaObject( metaObj );
return metaObj;
}
void* myTextEdit::qt_cast( const char* clname )
{
if ( !qstrcmp( clname, "myTextEdit" ) )
return this;
return QTextEdit::qt_cast( clname );
}
bool myTextEdit::qt_invoke( int _id, QUObject* _o )
{
switch ( _id - staticMetaObject()->slotOffset() ) {
case 0: append((QString)static_QUType_QString.get(_o+1)); break;
case 1: putLine(); break;
default:
return QTextEdit::qt_invoke( _id, _o );
}
return TRUE;
}
bool myTextEdit::qt_emit( int _id, QUObject* _o )
{
return QTextEdit::qt_emit(_id,_o);
}
#ifndef QT_NO_PROPERTIES
bool myTextEdit::qt_property( int id, int f, QVariant* v)
{
return QTextEdit::qt_property( id, f, v);
}
bool myTextEdit::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
#endif // QT_NO_PROPERTIES
#include "qtextedit.h"
#include "qtextedit.h"
class myTextEdit : public QTextEdit
{
public:
myTextEdit(QWidget *parent=0, const char *name=0);
~myTextEdit(){}
int count;
public slots:
void append(QString line);
void putLine(void);
private:
Q_OBJECT
};
Message 8 in thread
Creating the .h and putting the class declaration
class myTextEdit : public QTextEdit
{
Q_OBJECT
public:
myTextEdit(QWidget *parent=0, const char *name=0);
int count;
public slots:
void append(QString line);
void putLine(void);
};
caused syntax errors when making, but adding
#include <qtextedit.h>
at the beginning of the .h file stopped that and lo and behold my app
ran like I expected.
I don't understand the need for including the qtextedit.h file. In
main.cpp it is included AHEAD of the main.h include. Shouldn't that have
satisfied main.h's need for qtextedit.h? Or is it needed that specific
way for the moc generation?
Anyway, I got it to build and run and learned how.
Thanks to ALL who responded to this newbie.
tj
Paul Ruetz wrote:
> I assume you have only one source file, say 'main.cpp'.
>
> When you define signals or slots without having a header file, AFAIK
> you have to do two steps manually, as they are:
>
> 1. Call the 'moc' manually:
> moc main.cpp > moc_main.cpp
>
> 2. Include the 'moc_main.cpp' at the end of your 'main.cpp':
> #include "moc_main.cpp"
>
> To avoid these steps, always use header files when using signals/slots.
>
> Hope this helps,
>
> Paul
>
>
> tj wrote:
Message 9 in thread
tj wrote:
> Creating the .h and putting the class declaration
>
> class myTextEdit : public QTextEdit
> {
> Q_OBJECT
> public:
> myTextEdit(QWidget *parent=0, const char *name=0);
> int count;
>
> public slots:
> void append(QString line);
> void putLine(void);
>
> };
>
> caused syntax errors when making, but adding
> #include <qtextedit.h>
> at the beginning of the .h file stopped that and lo and behold my app
> ran like I expected.
>
> I don't understand the need for including the qtextedit.h file. In
> main.cpp it is included AHEAD of the main.h include. Shouldn't that
> have satisfied main.h's need for qtextedit.h? Or is it needed that
> specific way for the moc generation?
>
> Anyway, I got it to build and run and learned how.
>
> Thanks to ALL who responded to this newbie.
>
> tj
>
> Paul Ruetz wrote:
>
>> I assume you have only one source file, say 'main.cpp'.
>>
>> When you define signals or slots without having a header file, AFAIK
>> you have to do two steps manually, as they are:
>>
>> 1. Call the 'moc' manually:
>> moc main.cpp > moc_main.cpp
>>
>> 2. Include the 'moc_main.cpp' at the end of your 'main.cpp':
>> #include "moc_main.cpp"
>>
>> To avoid these steps, always use header files when using signals/slots.
>>
>> Hope this helps,
>>
>> Paul
>>
>>
>> tj wrote:
>
>
> --
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
the #include is scoped to main.cpp so the moc file that is created from
the .h file doesn't know about the textedit.h file which is why you
needed it in the main.h file. You should always put the #include (if
instantiating) or a forward reference(if only declaring a pointer) in
each file, you shouldn't make any assumtions about the order in which
files are processed.
--
[ signature omitted ]