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. Second call to setMenuBar does nothing
Forum Updated to NodeBB v4.3 + New Features

Second call to setMenuBar does nothing

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 585 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.
  • O Offline
    O Offline
    oneeyeman1
    wrote on last edited by
    #10

    Hi,
    I found the sample here: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/mainwindows/mdi?h=5.15. I will see if I can make t fail as I explained t.

    Now how can I build it?

    Just run:

    gcc -o mdi *.cpp

    ?

    I'd guess it will fail miserably... ;-)

    Thank you.

    JonBJ 1 Reply Last reply
    0
    • O oneeyeman1

      Hi,
      I found the sample here: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/mainwindows/mdi?h=5.15. I will see if I can make t fail as I explained t.

      Now how can I build it?

      Just run:

      gcc -o mdi *.cpp

      ?

      I'd guess it will fail miserably... ;-)

      Thank you.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #11

      @oneeyeman1
      You should install Qt Creator and open the .pro file as a (qmake) project. You need to set up your Compilation Kit, hopefully it will auto-detect the gcc stuff you have.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        oneeyeman1
        wrote on last edited by
        #12

        Hi guys,
        I didn't install Qt-Creator.

        Instead I ran "qmake". It generated Makefile.

        Then I ran "make". And this is what I got:

        igor@IgorsGentoo ~/sample $ make
        g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o main.o main.cpp
        In file included from mainwindow.h:53,
                         from mainwindow.h:53,
        ................................................................
                         from main.cpp:5:
        mainwindow.h:51:21: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
           51 | #include <QtWidgets>
              |                     ^
        mainwindow.h:53:24: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
           53 | #include "mainwindow.h"
              |                        ^
        mainwindow.h:54:22: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
           54 | #include "mdichild.h"
              |                      ^
        In file included from mainwindow.h:54,
        ......................................................................................................
                         from mainwindow.h:53,
                         from main.cpp:5:
        mdichild.h:54:21: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
           54 | #include <QTextEdit>
              |                     ^
        ^Cmake: *** wait: No child processes.  Stop.
        make: *** Waiting for unfinished jobs....
        make: *** wait: No child processes.  Stop.
        igor@IgorsGentoo ~/sample $
        

        How do I fix it?

        Thank you.

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #13

          Don't recursivly include headers, use include guards to make sure the header is not included more than once. Basic c++ stuff, nothing Qt specific.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          O 1 Reply Last reply
          2
          • O oneeyeman1

            Hi guys,
            I didn't install Qt-Creator.

            Instead I ran "qmake". It generated Makefile.

            Then I ran "make". And this is what I got:

            igor@IgorsGentoo ~/sample $ make
            g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o main.o main.cpp
            In file included from mainwindow.h:53,
                             from mainwindow.h:53,
            ................................................................
                             from main.cpp:5:
            mainwindow.h:51:21: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
               51 | #include <QtWidgets>
                  |                     ^
            mainwindow.h:53:24: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
               53 | #include "mainwindow.h"
                  |                        ^
            mainwindow.h:54:22: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
               54 | #include "mdichild.h"
                  |                      ^
            In file included from mainwindow.h:54,
            ......................................................................................................
                             from mainwindow.h:53,
                             from main.cpp:5:
            mdichild.h:54:21: error: #include nested depth 200 exceeds maximum of 200 (use -fmax-include-depth=DEPTH to increase the maximum)
               54 | #include <QTextEdit>
                  |                     ^
            ^Cmake: *** wait: No child processes.  Stop.
            make: *** Waiting for unfinished jobs....
            make: *** wait: No child processes.  Stop.
            igor@IgorsGentoo ~/sample $
            

            How do I fix it?

            Thank you.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #14

            @oneeyeman1
            I do not know whether you made changes to that example or there is a problem with it (which I would doubt).

            In any case, here is a completely standalone single source file program which changes the menubar:

            #include <QApplication>
            #include <QMainWindow>
            #include <QMenuBar>
            #include <QTimer>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                QMainWindow w;
            
                QMenuBar *menuBar1 = new QMenuBar();
                menuBar1->addMenu("menuBar1");
                w.setMenuBar(menuBar1);
            
                QMenuBar *menuBar2 = new QMenuBar();
                menuBar2->addMenu("menuBar2");
                w.setMenuBar(menuBar2);
            
                w.show();
            
                QMenuBar *menuBar3 = new QMenuBar();
                menuBar3->addMenu("menuBar3");
                QTimer::singleShot(3000, [&w, menuBar3]() { w.setMenuBar(menuBar3); });
            
                return a.exec();
            }
            

            Presumably you can compile and link this, perhaps just as you have done for any wxWidgets you currently have.

            The code starts with one menubar, replaces it with a second one immediately, and then replaces it with a third after 3 seconds. Needless to say it works as expected for me (Ubuntu 22.04, Qt 6.x, and I would expect it to work with any Qt version including your Qt5). You might start by checking this for yourself. If you then think that, say, MDI is required to show a problem then it will need altering for that.

            O 1 Reply Last reply
            2
            • JonBJ JonB

              @oneeyeman1
              I do not know whether you made changes to that example or there is a problem with it (which I would doubt).

              In any case, here is a completely standalone single source file program which changes the menubar:

              #include <QApplication>
              #include <QMainWindow>
              #include <QMenuBar>
              #include <QTimer>
              
              int main(int argc, char *argv[])
              {
                  QApplication a(argc, argv);
                  QMainWindow w;
              
                  QMenuBar *menuBar1 = new QMenuBar();
                  menuBar1->addMenu("menuBar1");
                  w.setMenuBar(menuBar1);
              
                  QMenuBar *menuBar2 = new QMenuBar();
                  menuBar2->addMenu("menuBar2");
                  w.setMenuBar(menuBar2);
              
                  w.show();
              
                  QMenuBar *menuBar3 = new QMenuBar();
                  menuBar3->addMenu("menuBar3");
                  QTimer::singleShot(3000, [&w, menuBar3]() { w.setMenuBar(menuBar3); });
              
                  return a.exec();
              }
              

              Presumably you can compile and link this, perhaps just as you have done for any wxWidgets you currently have.

              The code starts with one menubar, replaces it with a second one immediately, and then replaces it with a third after 3 seconds. Needless to say it works as expected for me (Ubuntu 22.04, Qt 6.x, and I would expect it to work with any Qt version including your Qt5). You might start by checking this for yourself. If you then think that, say, MDI is required to show a problem then it will need altering for that.

              O Offline
              O Offline
              oneeyeman1
              wrote on last edited by
              #15

              @JonB ,

              When I try to compile my program I'm doing "../configure && make -j3".

              I can copy the code you posted and just run make, but I presume it will fail as it need the include and library paths.

              Can you give me a proper way to build?

              Thank you.

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                Don't recursivly include headers, use include guards to make sure the header is not included more than once. Basic c++ stuff, nothing Qt specific.

                O Offline
                O Offline
                oneeyeman1
                wrote on last edited by
                #16

                @Christian-Ehrlicher

                What's interesting is that the sample code I'm trying to compile is not using setMenuBar() call.

                I wonder how it works without it...

                Thank you.

                JonBJ 1 Reply Last reply
                0
                • O oneeyeman1

                  @Christian-Ehrlicher

                  What's interesting is that the sample code I'm trying to compile is not using setMenuBar() call.

                  I wonder how it works without it...

                  Thank you.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #17

                  @oneeyeman1
                  You do not normally need setMenuBar(). QMainWindow creates one if you access menuBar(). Then again, I do not know of any code which swaps/uses multiple menubars, which you say is your use case.

                  O 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @oneeyeman1
                    You do not normally need setMenuBar(). QMainWindow creates one if you access menuBar(). Then again, I do not know of any code which swaps/uses multiple menubars, which you say is your use case.

                    O Offline
                    O Offline
                    oneeyeman1
                    wrote on last edited by
                    #18

                    @JonB ,

                    Imagine you are working in the IDE,

                    You are wring a source code and then realize you want too add some bitmap.

                    You go to add one, but you menu bar needs to change accordingly.

                    Thais just one example. In the MDI world its actually expected to change menu bar in accordance to the document you have open.

                    Thank you.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by Christian Ehrlicher
                      #19

                      This is mostly done through https://doc.qt.io/qt-6/qaction.html#visible-prop and https://doc.qt.io/qt-6/qaction.html#enabled-prop but not by replacing the entire menu bar...
                      Please provide a minimal, compilable example to reproduce your problem (without wxwhatever) - @JonB 's example works fine so proove us and Qt wrong.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      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