Results 1 to 12 of 12

Thread: How to extend a class ?

  1. #1
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to extend a class ?

    Hello !

    It's my first post so please be patient .

    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 :
    Qt Code:
    1. // promoted widget QListView -> QListViewExt
    2. #ifndef QLISTVIEWEXT_H
    3. #define QLISTVIEWEXT_H
    4.  
    5. #include <qlistview.h>
    6.  
    7.  
    8. class QListViewExt : public QListView
    9. {
    10. Q_OBJECT
    11. public:
    12. QListViewExt(QWidget *parent = 0, const char *name = 0);
    13. ~QListViewExt();
    14. };
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    and the associated moc file where the problem is :
    Qt Code:
    1. /****************************************************************************
    2. ** Meta object code from reading C++ file 'qlistviewext.h'
    3. **
    4. ** Created: dim. 25. juin 10:56:43 2006
    5. ** by: The Qt Meta Object Compiler version 59 (Qt 4.1.3)
    6. **
    7. ** WARNING! All changes made in this file will be lost!
    8. *****************************************************************************/
    9.  
    10. #include "qlistviewext.h"
    11. #if !defined(Q_MOC_OUTPUT_REVISION)
    12. #error "The header file 'qlistviewext.h' doesn't include <QObject>."
    13. #elif Q_MOC_OUTPUT_REVISION != 59
    14. #error "This file was generated using the moc from 4.1.3. It"
    15. #error "cannot be used with the include files from this version of Qt."
    16. #error "(The moc has changed too much.)"
    17. #endif
    18.  
    19. // The problem is at this line
    20. // The problem is at this line
    21. static const uint qt_meta_data_QListViewExt[] = {
    22. // error : 'uint' does not name a type
    23. // error : 'uint' does not name a type
    24.  
    25. // content:
    26. 1, // revision
    27. 0, // classname
    28. 0, 0, // classinfo
    29. 0, 0, // methods
    30. 0, 0, // properties
    31. 0, 0, // enums/sets
    32.  
    33. 0 // eod
    34. };
    35.  
    36. static const char qt_meta_stringdata_QListViewExt[] = {
    37. "QListViewExt\0"
    38. };
    39.  
    40. const QMetaObject QListViewExt::staticMetaObject = {
    41. { &QListView::staticMetaObject, qt_meta_stringdata_QListViewExt,
    42. // The problem is at this line
    43. // The problem is at this line
    44. qt_meta_data_QListViewExt, 0 }
    45. // error : : 'qt_meta_data_QListViewExt' was not declared in this scope
    46. // error : : 'qt_meta_data_QListViewExt' was not declared in this scope
    47. };
    48.  
    49. const QMetaObject *QListViewExt::metaObject() const
    50. {
    51. return &staticMetaObject;
    52. }
    53.  
    54. void *QListViewExt::qt_metacast(const char *_clname)
    55. {
    56. if (!_clname) return 0;
    57. if (!strcmp(_clname, qt_meta_stringdata_QListViewExt))
    58. return static_cast<void*>(const_cast<QListViewExt*>(this));
    59. return QListView::qt_metacast(_clname);
    60. }
    61.  
    62. int QListViewExt::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
    63. {
    64. _id = QListView::qt_metacall(_c, _id, _a);
    65. if (_id < 0)
    66. return _id;
    67. return _id;
    68. }
    To copy to clipboard, switch view to plain text mode 
    (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
    Last edited by agent007se; 26th June 2006 at 16:21.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    I think the problem is because you forgot the semi-colon at the end of your class declaration.

  3. #3
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    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 !

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Quote Originally Posted by agent007se
    Conclusion... that is a little more difficult !
    How do you build your application? Do you use qmake?

  5. #5
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Quote Originally Posted by jacek
    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Quote Originally Posted by agent007se
    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?
    Last edited by jacek; 26th June 2006 at 19:30.

  7. #7
    Join Date
    May 2006
    Location
    Bangalore
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Try putting this on line 18 of MOC'ed file.

    Qt Code:
    1. typedef unsigned int uint
    To copy to clipboard, switch view to plain text mode 

    Then we might get other errors due to some Qt include related configuration.
    The Keyboard Is Mightier Than The Sword!

  8. #8
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to extend a class ?

    Quote Originally Posted by bits
    Try putting this on line 18 of MOC'ed file.

    Qt Code:
    1. typedef unsigned int uint
    To copy to clipboard, switch view to plain text mode 

    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.rdata$_ZTV12QListViewExt[vtable for QListViewExt]+0x14): undefined reference to `QListViewExt::~QListViewExt()'
    .objs\moc_qlistviewext.o:moc_qlistviewext.cpp.rdata$_ZTV12QListViewExt[vtable for QListViewExt]+0x18): undefined reference to `QListViewExt::~QListViewExt()'
    .objs\moc_qlistviewext.o:moc_qlistviewext.cpp.rdata$_ZTV12QListViewExt[vtable for QListViewExt]+0x190): undefined reference to `non-virtual thunk to QListViewExt::~QListViewExt()'
    .objs\moc_qlistviewext.o:moc_qlistviewext.cpp.rdata$_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 ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Quote Originally Posted by agent007se
    undefined reference to `QListViewExt::~QListViewExt()'
    Maybe you forgot to implement the destructor?

  10. #10
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Quote Originally Posted by jacek
    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 !!

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Quote Originally Posted by agent007se
    Please, can you give me a minimal implementation of qlistviewext.cpp in regard of the qlistviewext.h ?
    Qt Code:
    1. QListViewExt::QListViewExt( QWidget *parent, const char *name )
    2. : QListView( parent )
    3. {
    4. setObjectName( name );
    5. }
    6.  
    7. QListViewExt::~QListViewExt()
    8. {
    9. // empty
    10. }
    To copy to clipboard, switch view to plain text mode 
    Your constructor signature looks like if you were trying to use Qt3, not Qt4. Qt4 doesn't use name parameter in widget constructors.

  12. The following user says thank you to jacek for this useful post:

    agent007se (27th June 2006)

  13. #12
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extend a class ?

    Well, it work like a charm now .

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

    Thanks again !

Similar Threads

  1. How can i prevent class redefinition problem ?
    By ankurjain in forum General Programming
    Replies: 5
    Last Post: 26th May 2006, 02:35
  2. Replies: 2
    Last Post: 4th May 2006, 19:17
  3. Qt in other class
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2006, 17:08
  4. How to propagate from one class to another
    By mahe2310 in forum Qt Programming
    Replies: 15
    Last Post: 20th March 2006, 01:27
  5. Replies: 5
    Last Post: 15th March 2006, 07:33

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.