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->setValue("size", this->size());
    	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

  • Lifetime Qt Champion

    @cerr Well, because


    is not the same as


    and can't be implicitly converted.
    What you want is:

    QList <QListWidget *> wdgt;
    wdgt.append(this->findChild<QListWidget *>());

  • @jsulm Excellent! Thank you my friend!

Log in to reply