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]menuBar() not found?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]menuBar() not found?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.6k Views 2 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
    manny
    wrote on last edited by manny
    #1

    I was making a small test program, and came across an error that said that it can't find menuBar. here is the following code:

    #include "mainwindow.h"
    #include <QApplication>
    #include <QtWidgets>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QMainWindow win;
    QMenu *menu = menuBar()->addMenu(tr("&File"));
    menu->addSeparator();
    QHBoxLayout *box = new QHBoxLayout;
    box->addWidget(menu);
    win.setLayout(box);

    return a.exec();
    

    }
    any help is greatly appreciated

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      @manny said:
      You are calling global menuBar() function which does not exist

      QMenu *menu = menuBar()->addMenu(tr("&File"));

      you probably wanted

      QMenu *menu = win.menuBar()->addMenu(tr("&File"));

      1 Reply Last reply
      1
      • M Offline
        M Offline
        manny
        wrote on last edited by
        #3

        ok, i think i understand

        1 Reply Last reply
        0
        • M Offline
          M Offline
          manny
          wrote on last edited by manny
          #4

          sorry, but can someone also explain what is the difference between:

          action = menu->addSeparator()

          and:

          menu->addSeparator()

          I understand that in the first one action is assigned to separator, however they both do the same job, so what is the advantage of using one over the other. Is it maybe in the first one you can possibly hide the separator if you wanted to, or do something else to it?

          any help is, again, greatly appreciated

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

            Yes in
            action newaction= menu->addSeparator()
            you get newaction to set other properties on if needed, where as
            menu->addSeparator()
            you have no returned action to play with.

            1 Reply Last reply
            1
            • M Offline
              M Offline
              manny
              wrote on last edited by
              #6

              thanks for clearing that up

              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