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

navid navid n_nnavid at yahoo.com
Sat Oct 31 10:47:41 CET 2009


thanks qt professionals for the favor to qt newbies  :)



----- Original Message ----
From: Paul Colby <qt at colby.id.au>
To: navid navid <n_nnavid at yahoo.com>
Cc: qt-interest at trolltech.com
Sent: Sat, October 31, 2009 12:10:50 PM
Subject: Re: [Qt-interest] error: passing `const QLabel' as `this' argument of  `void QLabel::setText(const QString&)' discards qualifiers

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