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. metaObject()->className() doesn't find QLabel

metaObject()->className() doesn't find QLabel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 770 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mar0029
    wrote on last edited by
    #1

    Hello!

    I am using the following code to find all QLayouts within a main layout and then all widgets within those layouts.

    if(!allSubLayouts.empty())
    {
        int size = allSubLayouts.size();
        for(int i = 0; i < size; i ++)  // this loop hides all of the layouts that are currently present. If there are no layouts, nothing happens
        {
            for(int j = 0; j < allSubLayouts.at(i)->count(); ++j)
            {
    
                QWidget *w = allSubLayouts.at(i)->itemAt(j)->widget();
                if(w != NULL)
                {
                    qDebug() << "The className of the object is " ;
                    qDebug() << allSubLayouts.at(i)->itemAt(j)->widget()->metaObject()->className();
    
                    w->setVisible(false);
                    //delete w;
                }
            }
        }
    

    When I run the code, everything except the QLabel classnames are displayed in the qDebug statement.

    Why doesn't widget()->metaObject()->className(); produce QLabels?

    kshegunovK 1 Reply Last reply
    0
    • M mar0029

      Hello!

      I am using the following code to find all QLayouts within a main layout and then all widgets within those layouts.

      if(!allSubLayouts.empty())
      {
          int size = allSubLayouts.size();
          for(int i = 0; i < size; i ++)  // this loop hides all of the layouts that are currently present. If there are no layouts, nothing happens
          {
              for(int j = 0; j < allSubLayouts.at(i)->count(); ++j)
              {
      
                  QWidget *w = allSubLayouts.at(i)->itemAt(j)->widget();
                  if(w != NULL)
                  {
                      qDebug() << "The className of the object is " ;
                      qDebug() << allSubLayouts.at(i)->itemAt(j)->widget()->metaObject()->className();
      
                      w->setVisible(false);
                      //delete w;
                  }
              }
          }
      

      When I run the code, everything except the QLabel classnames are displayed in the qDebug statement.

      Why doesn't widget()->metaObject()->className(); produce QLabels?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @mar0029
      It seems okay, but have you tried something simpler like QObject::findChildren?

      QList<QWidget *> items = findChildren<QWidget *>();
      foreach (QWidget * item, items)
          qDebug() << item->metaObject()->className();
      

      Kind regards.

      Read and abide by the Qt Code of Conduct

      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