[Qt-interest] error: passing `const QLabel' as `this' argument of `void QLabel::setText(const QString&)' discards qualifiers

Paul Colby qt at colby.id.au
Sat Oct 31 09:40:50 CET 2009


Glad to hear you're progressing :)

> void MyClass::on_pushButton_pressed()
> {
> QList<QCheckBox *> * checkbox_list;
> QList<QLabel *> * label_list;
> label_list->append(ui->label1);
> ...
> MyFunction(checkbox_list,label_list);
>
> }

The problem here is that checkbox_list and label_list are both
uninitialized pointers!

If you really do want checkbox_list and label_list to be pointers,
then initialize them using something like this:

void MyClass::on_pushButton_pressed()
{
    QList<QCheckBox *> * checkbox_list = new QList<QCheckBox *>;
    QList<QLabel *> * label_list = new QList<QLabel *>;
    label_list->append(ui->label1);
    ...
    MyFunction(checkbox_list,label_list);
    delete checkbox_list;
    delete label_list;
}

Alternatively, don't make them pointers at all... eg:

void MyClass::on_pushButton_pressed()
{
    QList<QCheckBox *> checkbox_list;
    QList<QLabel *> label_list;
    label_list.append(ui->label1);
    ...
    MyFunction(&checkbox_list,&label_list);
}

pc.
--
http://colby.id.au



More information about the Qt-interest-old mailing list