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. Does QMenu::addAction return 0 pointer?
Qt 6.11 is out! See what's new in the release blog

Does QMenu::addAction return 0 pointer?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.5k 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.
  • P Offline
    P Offline
    Paul Busovikov
    wrote on last edited by
    #1

    subj

    is that code safe?

    QAction* a = menu->addAction( "some action" );
    a->doSomething();
    

    should I check it before or it is unnecessary?

    if ( a ) a->doSomething();
    

    or the same about addMenu

    I haven't found mentions about it on http://doc.qt.io/qt-5/qmenu.html
    only about actionAt which does return 0

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      It is unnecessary.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Only in case of out of memory, it could in theory return null but might assert and close
        anyway. So would be waste to check as in 99% of all cases it will be added.

        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