[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 01:46:37 CET 2009


(don't forget to reply-all ie include qt-interest in your replies)

On Sat, Oct 31, 2009 at 11:02 AM, navid navid <n_nnavid at yahoo.com> wrote:
> 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'

The correct de-reference would be like:

(*label_list)[i].setText("checked");

But it looks like the problem with QList::value() and
QList::operator[] is still going to be that they both try to return a
copy of the the QList template type "T" (QLabel in this case).  And as
the compliler error said above, there's no accessible
QLabel::QLabel(const QLabel&) copy constructor (it's private
apparently).

So, the thing to do instead, would be to make your label_list store
pointers rather than QLabel objects themselves.

eg, you probably have something like:

QList<QLabel> *label_list;

Try changing that to:

QList<QLabel *> *label_list; // Note the "QLabel *".

Then you can do:

label_list->at(i)->setText("checked");

just as you originally tried (note the second "->" instead of "." though).

You will, of course, need to update the rest of your code since you'll
have changed QList's template type from QLabel to QLabel pointer.

pc.

>
> 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
>>
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
>
> --
> http://colby.id.au
>
>
>
>
>



-- 
http://colby.id.au




More information about the Qt-interest-old mailing list