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. [Solved]what does this syntax mean in c++?
Forum Updated to NodeBB v4.3 + New Features

[Solved]what does this syntax mean in c++?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 2.4k 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.
  • W Offline
    W Offline
    whitesong
    wrote on last edited by
    #1

    I want to know what this syntax says:

    @(void) new ClassName();@
    

    the syntax above is used in this snip code for populate a widget.

    @ void populateTree(QTreeWidget *treeWidget)
    {
    QStringList labels;
    labels << QObject::tr("Terms") << QObject::tr("Pages");

        treeWidget->setHeaderLabels(labels);
        treeWidget->header()->setResizeMode(QHeaderView::Stretch);
        treeWidget->setWindowTitle(QObject::tr("XML Stream Writer"));
        treeWidget->show();
    
        (void) new QTreeWidgetItem(treeWidget,
                QStringList() << "sidebearings" << "10, 34-35, 307-308");
        QTreeWidgetItem *subterm = new QTreeWidgetItem(treeWidget,
                QStringList() << "subtraction");
        (void) new QTreeWidgetItem(subterm,
                QStringList() << "of pictures" << "115, 244");
        (void) new QTreeWidgetItem(subterm,
                QStringList() << "of vectors" << "9");
    }@
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      coyotte508
      wrote on last edited by
      #2

      The (void) doesn't do anything, it just removes some warnings for some IDEs to tell it's normal the result of the "new" isn't stored in any variable.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        whitesong
        wrote on last edited by
        #3

        thanks. so in some IDEs "(void)" will be needed

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          It is not needed in any of the popular IDEs and compilers.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            [quote author="whitesong" date="1367141103"]thanks. so in some IDEs "(void)" will be needed[/quote]It's not really needed, but it's nice to get rid of compiler warnings.

            In this code below, your compiler might warn you that x and y are unused. :
            @
            void myFunction(int x)
            {
            int y = 1;
            return; // Produces a warning that x and y are unused
            }
            @

            But, calling (void) tells the compiler to "do nothing" with the variables, so it won't complain:

            @
            void myFunction(int x)
            {
            int y = 1;

            // Prevents warnings
            (void) x;
            (void) y;
            
            return;
            

            }
            @

            Qt has its own macro to do this, instead of (void). The code below has exactly the same effect as the code above:
            @
            void myFunction(int x)
            {
            int y = 1;

            // Prevents warnings
            Q_UNUSED(x);
            Q_UNUSED(y);
            
            return;
            

            }
            @

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • W Offline
              W Offline
              whitesong
              wrote on last edited by
              #6

              Oh thanks again everyone.
              I really understand what is going on with your explanation .

              1 Reply Last reply
              0
              • W Offline
                W Offline
                whitesong
                wrote on last edited by
                #7

                Oh thanks again everyone.
                I really understand what is going on with your explanation.

                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