[Qt-interest] Fw: 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 07:17:57 CET 2009


> Can you show us how you've declared label_list?

class MyClass: public QObject 
{
Q_OBJECT

public:
MyClass(QObject * parent=0);
~MyClass();

private:
void MyFunction(QList<QCheckBox> * checkbox_list, QList<QLabel> * label_list);

};


nn




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

> by the way, why {checkbox_list->at(i).checkState()} with {at} is compiled  with no error?

that's because QCheckBox::checkState is a "const" function, so it can
be called on constant QCheckBox instances, whereas QLabel::setText is
not declared "const", so it cannot be called on constant QLabel
instances (not that QList::at() returns a "const" reference).

Can you show us how you've declared label_list?

pc.

>
>
>
> ----- Forwarded Message ----
> From: navid navid <n_nnavid at yahoo.com>
> To: Paul Colby <qt at colby.id.au>
> Sent: Sat, October 31, 2009 3:32:50 AM
> Subject: Re: [Qt-interest] error: passing `const QLabel' as `this' argument of  `void QLabel::setText(const QString&)' discards qualifiers
>
> Dear Mr Colby,
>
> Thanks for your email. but it does not work.
>
> label_list->value(i).setText("checked"); // error: `QLabel::QLabel(const QLabel&)' is private
>
> label_list[i].setText("checked"); // error: 'class QList<QLabel>' has no member named 'setText'
> *label_list[i].setText("checked"); // error: 'class QList<QLabel>' has no member named 'setText'
> &label_list[i].setText("checked"); // error: 'class QList<QLabel>' has no member named 'setText'
>
> Regards
> n. navid
>
>
>
> ----- 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 2:48:19 AM
> Subject: Re: [Qt-interest] error: passing `const QLabel' as `this' argument of  `void QLabel::setText(const QString&)' discards qualifiers
>
> QList::at() does indeed return a const T &, so that makes sense ;)
>
> Try either of these instead:
>
> label_list->value(i).setText("checked"); // or...
> label_list[i].setText("checked"); // Might need to de-reference the
> list_label pointer first?
>
> paul.
>
> On Sat, Oct 31, 2009 at 9:49 AM, navid navid <n_nnavid at yahoo.com> wrote:
>> Hello,
>>
>> please comments for removing the error:
>>
>> void MyClass::MyFunction(QList<QCheckBox> * checkbox_list, QList<QLabel> * label_list)
>> {
>>    for(int i=0;i<checkbox_list->count() ;i++)
>>      if (checkbox_list->at(i).checkState()){
>>         label_list->at(i).setText("checked"); // error: passing `const QLabel' as `this' argument of `void QLabel::setText(const QString&)' discards qualifiers
>>      }
>>  }
>>
>>
>>
>> Thanks in advance
>> n. navid


      



More information about the Qt-interest-old mailing list