|
|
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
--
Erik Kaffehr erik.kaffehr@xxxxxxxxxx alt. ekr@xxxxxx
Mariebergsvägen 53 +46 155 219338 (home)
S-611 66 Nyköping +46 155 263515 (office)
Sweden -- Message sent using 100% recycled electrons --
Makefile
Description: Text Data
main.cpp
Description: Text Data
aaa.pro
Description: Text document
moc_main.cpp
Description: Text Data
main.h
Description: Text Data
|
|