Results 1 to 3 of 3

Thread: Using QObjectPointerList in Qt3

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Using QObjectPointerList in Qt3

    I am getting a wierd compiler error in this code:

    Qt Code:
    1. const QObjectList *l = boxLayout->children();
    2.  
    3. for ( unsigned int i = topLine; i != l->count(); i++ )
    4. {
    5. QObject *obj = l->at(i);
    6. if( !((PositionElementLine*)obj)->isChecked() )
    7. firstUnchecked = i;
    8. }
    To copy to clipboard, switch view to plain text mode 

    gcc objects to line 5 with this message:

    error: passing 'const QObjectList' as 'this' argument of 'type* QPtrList<type>::at(uint) [with type = QObject]' discards qualifiers

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QObjectPointerList in Qt3

    Quote Originally Posted by importantman View Post
    I am getting a wierd compiler error in this code:

    Qt Code:
    1. const QObjectList *l = boxLayout->children();
    2.  
    3. for ( unsigned int i = topLine; i != l->count(); i++ )
    4. {
    5. QObject *obj = l->at(i);
    6. if( !((PositionElementLine*)obj)->isChecked() )
    7. firstUnchecked = i;
    8. }
    To copy to clipboard, switch view to plain text mode 

    gcc objects to line 5 with this message:
    Did you try typecsating
    Qt Code:
    1. const QObjectList *l = (QObjectList *)boxLayout->children();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using QObjectPointerList in Qt3

    Quote Originally Posted by importantman View Post
    I am getting a wierd compiler error in this code:

    Qt Code:
    1. const QObjectList *l = boxLayout->children();
    2.  
    3. for ( unsigned int i = topLine; i != l->count(); i++ )
    4. {
    5. QObject *obj = l->at(i);
    6. if( !((PositionElementLine*)obj)->isChecked() )
    7. firstUnchecked = i;
    8. }
    To copy to clipboard, switch view to plain text mode 

    gcc objects to line 5 with this message:
    There are two solutions.
    If PositionElementLine::isChecked() is a const function(actually it has to be if the classes are well designed) then use the following at the respective place
    Qt Code:
    1. const QObject *obj = l->at(i);
    2. if( !((const PositionElementLine*)obj)->isChecked() )
    3. firstUnchecked = i;
    To copy to clipboard, switch view to plain text mode 

    If PositionElementLine::isChecked() is not a const function then use type casting as follows
    Qt Code:
    1. QObject *obj = const_cast<QObject*>(l->at(i));
    2. if( !((PositionElementLine*)obj)->isChecked() )
    3. firstUnchecked = i;
    To copy to clipboard, switch view to plain text mode 
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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.