Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why do I get a " conversion from ‘QListWidget*’ to non-scalar type ‘QList<QListWidget*>’ requested" error

Why do I get a " conversion from ‘QListWidget*’ to non-scalar type ‘QList<QListWidget*>’ requested" error

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 800 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by cerr
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • cerrC cerr

      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

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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 *>());
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      cerrC 1 Reply Last reply
      1
      • jsulmJ jsulm

        @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 *>());
        
        cerrC Offline
        cerrC Offline
        cerr
        wrote on last edited by
        #3

        @jsulm Excellent! Thank you my friend!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved