
Originally Posted by
importantman
I am getting a wierd compiler error in this code:
const QObjectList *l = boxLayout->children();
for ( unsigned int i = topLine; i != l->count(); i++ )
{
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
}
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;
}
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
if( !((const PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
const QObject *obj = l->at(i);
if( !((const PositionElementLine*)obj)->isChecked() )
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
QObject *obj
= const_cast<QObject
*>
(l
->at
(i
));
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
QObject *obj = const_cast<QObject*>(l->at(i));
if( !((PositionElementLine*)obj)->isChecked() )
firstUnchecked = i;
To copy to clipboard, switch view to plain text mode
Bookmarks