Results 1 to 12 of 12

Thread: How to extend a class ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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
  •  
Qt is a trademark of The Qt Company.