PDA

View Full Version : How to extend a class ?



agent007se
26th June 2006, 14:05
Hello !

It's my first post so please be patient :D.

I work on Code::Blocks and Qt 4.1.

I wonder how it is possible to extend, for exemple, a QListView ?

Here is what I tried without positive result :

QListViewExt.h :


// promoted widget QListView -> QListViewExt
#ifndef QLISTVIEWEXT_H
#define QLISTVIEWEXT_H

#include <qlistview.h>


class QListViewExt : public QListView
{
Q_OBJECT
public:
QListViewExt(QWidget *parent = 0, const char *name = 0);
~QListViewExt();
};

#endif


and the associated moc file where the problem is :


/************************************************** **************************
** Meta object code from reading C++ file 'qlistviewext.h'
**
** Created: dim. 25. juin 10:56:43 2006
** by: The Qt Meta Object Compiler version 59 (Qt 4.1.3)
**
** WARNING! All changes made in this file will be lost!
************************************************** ***************************/

#include "qlistviewext.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'qlistviewext.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 59
#error "This file was generated using the moc from 4.1.3. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

// The problem is at this line
// The problem is at this line
static const uint qt_meta_data_QListViewExt[] = {
// error : 'uint' does not name a type
// error : 'uint' does not name a type

// content:
1, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
0, 0, // properties
0, 0, // enums/sets

0 // eod
};

static const char qt_meta_stringdata_QListViewExt[] = {
"QListViewExt\0"
};

const QMetaObject QListViewExt::staticMetaObject = {
{ &QListView::staticMetaObject, qt_meta_stringdata_QListViewExt,
// The problem is at this line
// The problem is at this line
qt_meta_data_QListViewExt, 0 }
// error : : 'qt_meta_data_QListViewExt' was not declared in this scope
// error : : 'qt_meta_data_QListViewExt' was not declared in this scope
};

const QMetaObject *QListViewExt::metaObject() const
{
return &staticMetaObject;
}

void *QListViewExt::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_QListViewExt))
return static_cast<void*>(const_cast<QListViewExt*>(this));
return QListView::qt_metacast(_clname);
}

int QListViewExt::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QListView::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
return _id;
}

(so there are two erros (in red comments))

If you need more information... just ask ;) !

Thanks !

edit:
1) added semi-colon at and of class definition

munna
26th June 2006, 14:15
I think the problem is because you forgot the semi-colon at the end of your class declaration.

agent007se
26th June 2006, 16:28
Thanks for that notification but that doesn't solve the problem. In fact, I think the compiler would show it if it was gone to that line !

Conclusion... that is a little more difficult !

jacek
26th June 2006, 17:05
Conclusion... that is a little more difficult !
How do you build your application? Do you use qmake?

agent007se
26th June 2006, 18:06
How do you build your application? Do you use qmake?

I use a little tool called qt-prebuild which is fully functionnal because I already compiled other Qt based programs very well without difficulties so it must call qmake nicely to do that.

edit: of course that program run uic.exe, moc.exe and so on... all what's needed to compile.

jacek
26th June 2006, 19:24
I already compiled other Qt based programs very well without difficulties so it must call qmake nicely to do that.
Are you sure that there are no other errors? Maybe your compiler can't find Qt headers?

bits
26th June 2006, 19:36
Try putting this on line 18 of MOC'ed file.


typedef unsigned int uint

Then we might get other errors due to some Qt include related configuration.

agent007se
26th June 2006, 20:49
Try putting this on line 18 of MOC'ed file.


typedef unsigned int uint

Then we might get other errors due to some Qt include related configuration.

That wasn't the problem !

I solved the problem with deleting all "crap" files that weren't needed anymore and now it works BUT I have a new problem which fit nicely with the title of this topic so we can continue now :

here is the output :



Linking executable: C:\test\app.exe
.objs\moc_qlistviewext.o:moc_qlistviewext.cpp:(.rd ata$_ZTV12QListViewExt[vtable for QListViewExt]+0x14): undefined reference to `QListViewExt::~QListViewExt()'
.objs\moc_qlistviewext.o:moc_qlistviewext.cpp:(.rd ata$_ZTV12QListViewExt[vtable for QListViewExt]+0x18): undefined reference to `QListViewExt::~QListViewExt()'
.objs\moc_qlistviewext.o:moc_qlistviewext.cpp:(.rd ata$_ZTV12QListViewExt[vtable for QListViewExt]+0x190): undefined reference to `non-virtual thunk to QListViewExt::~QListViewExt()'
.objs\moc_qlistviewext.o:moc_qlistviewext.cpp:(.rd ata$_ZTV12QListViewExt[vtable for QListViewExt]+0x194): undefined reference to `non-virtual thunk to QListViewExt::~QListViewExt()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 10 seconds)
0 errors, 0 warnings


I think that the better thing to do is restarting a new and clean project file because I'll use a QTreeWidget which have the function I wanted so that I don't need to extend anything !

Thanks for trying to help me !

Oh, last thing, can you say me if there is a "default" structure of tree in QTreeView like in QTreeWidget ?

jacek
26th June 2006, 21:22
undefined reference to `QListViewExt::~QListViewExt()'
Maybe you forgot to implement the destructor?

agent007se
27th June 2006, 08:49
Maybe you forgot to implement the destructor?

Please, can you give me a minimal implementation of qlistviewext.cpp in regard of the qlistviewext.h ?

I have some difficulties to do that because I'm just beginning with "serious" things with Qt !!

I'll give you a thank just after that :D !!

jacek
27th June 2006, 11:33
Please, can you give me a minimal implementation of qlistviewext.cpp in regard of the qlistviewext.h ?

QListViewExt::QListViewExt( QWidget *parent, const char *name )
: QListView( parent )
{
setObjectName( name );
}

QListViewExt::~QListViewExt()
{
// empty
}
Your constructor signature looks like if you were trying to use Qt3, not Qt4. Qt4 doesn't use name parameter in widget constructors.

agent007se
27th June 2006, 12:09
Well, it work like a charm now :D.

- Removed the name because I was using an old howto !
- Added the desctructor

Thanks again ;) !