View Full Version : Using QObjectPointerList in Qt3
importantman
6th June 2007, 03:20
I am getting a wierd compiler error in this code:
const QObjectList *l = boxLayout->children();
for ( unsigned int i = topLine; i != l->count(); i++ )
{
QObject *obj = l->at(i);
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
}
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
vermarajeev
6th June 2007, 09:32
I am getting a wierd compiler error in this code:
const QObjectList *l = boxLayout->children();
for ( unsigned int i = topLine; i != l->count(); i++ )
{
QObject *obj = l->at(i);
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
}
gcc objects to line 5 with this message:
Did you try typecsating
const QObjectList *l = (QObjectList *)boxLayout->children();
Gopala Krishna
6th June 2007, 09:57
I am getting a wierd compiler error in this code:
const QObjectList *l = boxLayout->children();
for ( unsigned int i = topLine; i != l->count(); i++ )
{
QObject *obj = l->at(i);
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
}
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
const QObject *obj = l->at(i);
if( !((const PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
If PositionElementLine::isChecked() is not a const function then use type casting as follows
QObject *obj = const_cast<QObject*>(l->at(i));
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.