Second call to setMenuBar does nothing
-
wrote 22 days ago last edited by
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.
-
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.
wrote 22 days ago last edited by@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. -
wrote 22 days ago last edited by
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.
-
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.
-
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.
wrote 21 days ago last edited by JonB 21 days ago@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.
-
@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.
wrote 21 days ago last edited by@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.
-
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.
wrote 21 days ago last edited byWhat'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.
-
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.
wrote 21 days ago last edited by@oneeyeman1
You do not normally needsetMenuBar()
.QMainWindow
creates one if you accessmenuBar()
. Then again, I do not know of any code which swaps/uses multiple menubars, which you say is your use case. -
@oneeyeman1
You do not normally needsetMenuBar()
.QMainWindow
creates one if you accessmenuBar()
. Then again, I do not know of any code which swaps/uses multiple menubars, which you say is your use case.wrote 21 days ago last edited by@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.
-
Lifetime Qt Championwrote 20 days ago last edited by Christian Ehrlicher 9 days from now
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.
19/19