Why do I get a " conversion from ‘QListWidget*’ to non-scalar type ‘QList<QListWidget*>’ requested" error
-
Hi,
I've got dialogs with a QListWidget that is loaded with QListWidgetItems that are checkable. For now, I do not care about which one is checked and which one isn't, but instead, I just want to ierate through all the items in the widget but turns out, I can't even find the widget, what I have looks like:
QSettings *sttngs = new QSettings(QSettings::NativeFormat,QSettings::UserScope,"GNU","SCAPER",nullptr); sttngs->beginGroup(nme_get()); sttngs->setValue("size", this->size()); sttngs->endGroup(); sttngs->beginGroup("tooloptions"); QList <QListWidget *> wdgt = this->findChild<QListWidget *>();
and what I get for the bottom line is a compiler error:
error: conversion from ‘QListWidget*’ to non-scalar type ‘QList<QListWidget*>’ requested
pointing at:QList <QListWidget *> wdgt = this->findChild<QListWidget *>(); ^
and I'm not exactly sure why, if someone could enlighten me, that would be great & appreciated
-
Hi,
I've got dialogs with a QListWidget that is loaded with QListWidgetItems that are checkable. For now, I do not care about which one is checked and which one isn't, but instead, I just want to ierate through all the items in the widget but turns out, I can't even find the widget, what I have looks like:
QSettings *sttngs = new QSettings(QSettings::NativeFormat,QSettings::UserScope,"GNU","SCAPER",nullptr); sttngs->beginGroup(nme_get()); sttngs->setValue("size", this->size()); sttngs->endGroup(); sttngs->beginGroup("tooloptions"); QList <QListWidget *> wdgt = this->findChild<QListWidget *>();
and what I get for the bottom line is a compiler error:
error: conversion from ‘QListWidget*’ to non-scalar type ‘QList<QListWidget*>’ requested
pointing at:QList <QListWidget *> wdgt = this->findChild<QListWidget *>(); ^
and I'm not exactly sure why, if someone could enlighten me, that would be great & appreciated
-
@cerr Well, because
QList<QListWidget*>
is not the same as
QListWidget*
and can't be implicitly converted.
What you want is:QList <QListWidget *> wdgt; wdgt.append(this->findChild<QListWidget *>());