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. Qmenu::findChild is not working properly
QtWS25 Last Chance

Qmenu::findChild is not working properly

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 781 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by Qt Enthusiast
    #1

    Hi All
    The QMenu findChild is not working properly

    QMenu* lMenu;
    QMenu* existingMenu = lMenu->findChild<QMenu*>(QString("A..."));
    if (!existingMenu)
    lMenu->addMenu("A...");

    Can someone help me to solve the same . In this case existing menu is always NULL athat is why A... gets added multiple times

    J.HilkJ 1 Reply Last reply
    0
    • Q Qt Enthusiast

      Hi All
      The QMenu findChild is not working properly

      QMenu* lMenu;
      QMenu* existingMenu = lMenu->findChild<QMenu*>(QString("A..."));
      if (!existingMenu)
      lMenu->addMenu("A...");

      Can someone help me to solve the same . In this case existing menu is always NULL athat is why A... gets added multiple times

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Qt-Enthusiast said in Qmenu::findChild is not working properly:

      findChild

      the string you define in findchild specifies the objectname. Newly, by code not designer, created Objects have an empty string as ObjectName.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      5
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        could you please code for me

        jsulmJ 1 Reply Last reply
        0
        • J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          untested.

          QMenu* lMenu;
          QMenu* existingMenu = lMenu->findChild<QMenu*>(QString("A..."));
          if (!existingMenu){
               existingMenu  = new  QMenu("A...");
               existingMenu->setObjectName("A...");
               lMenu->addMenu(existingMenu);
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • Q Qt Enthusiast

            could you please code for me

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Qt-Enthusiast said in Qmenu::findChild is not working properly:

            could you please code for me

            Could you please read documentation: http://doc.qt.io/qt-5/qobject.html#objectName-prop ?

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

            1 Reply Last reply
            2

            • Login

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