Solved [QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.
-
I have simple code with QMenu class:
QMenu* menu = new QMenu( mainWindow_ ) menu->setSizePolicy( QSizePolicy::Preferred, menu->sizePolicy().verticalPolicy() ); menu->setFixedWidth( QWIDGETSIZE_MAX ); menu->clear(); QAction* action; action = menu->addAction( tr( "Send report" ) ); action->setObjectName( "sendReport" ); action = menu->addAction( tr( "Show in folder" ) ); action->setObjectName( "showInFolder" ); menu->setSizePolicy( QSizePolicy::Fixed, menu->sizePolicy().verticalPolicy() ); menu->setFixedWidth( rect["width"].toInt() ); QSize screenSize = QApplication::desktop()->screenGeometry().size(); QPoint pos = mapToGlobal( QPoint( rect["x"].toInt(), rect["y"].toInt() + rect["height"].toInt() ) ); menu->popup( pos ); if( pos.y() + menu->height() > screenSize.height() ) { menu->move( mapToGlobal( QPoint( rect["x"].toInt(), rect["y"].toInt() - menu->height() ) ) ); } action = menu->exec(); if( action ) { if( action->objectName() == "sendReport" ) { OnSendReportTriggered(); } else if( action->objectName() == "showInFolder" ) { OnShowInFolderTriggered(); } }
Qt 5.9.7 build from source with Debug and Release variant.
On Debug variant QMenu after call menu->exec() does show correct.
On Release variant QMenu after call menu->exec() always return 0 (menu don't show).Build system on Debian and Ubuntu, try compilers: gcc5, gcc6, gcc7, clang6, clang7.
Please help. What the problem? -
Hi
Problem is solved.Menu closed in code info Application::eventFilter( QObject* object, QEvent* event ) on event == QEvent::FocusOut.
Thanks for all.
-
Hi and welcome to devnet,
Why are you calling popup and then exec ? That doesn't look really clean.
-
@SGaist said in [QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.:
Why are you calling popup and then exec ? That doesn't look really clean.
popup() only displays the menu.
exec() executes this menu. -
I'm guessing that "rect" is a variant that you are accessing to get the dimensions.
I would check the values of access , "x", "y" and "width" and "height". Its possible that in the debug version you are getting zero as a value, but in the release version you are getting garbage that may be interpreted as a negative integer.
In that case the position or size may not be visible. -
@kas_ru what @SGaist meant was this: http://doc.qt.io/qt-5/qmenu.html#exec - exec already shows the menu...
-
@mranger90 I checked, "rect" object in Debug and Release the same.
-
I think this is X11 issues.
Last news:/*! \overload Executes this menu synchronously. Pops up the menu so that the action \a action will be at the specified \e global position \a p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal(). This returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc). Note that all signals are emitted as usual. If you connect a QAction to a slot and call the menu's exec(), you get the result both via the signal-slot connection and in the return value of exec(). Common usage is to position the menu at the current mouse position: \snippet code/src_gui_widgets_qmenu.cpp 3 or aligned to a widget: \snippet code/src_gui_widgets_qmenu.cpp 4 or in reaction to a QMouseEvent *e: \snippet code/src_gui_widgets_qmenu.cpp 5 When positioning a menu with exec() or popup(), bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint() which calculates the proper size depending on the menu's current contents. \sa popup(), QWidget::mapToGlobal() */ QAction *QMenu::exec(const QPoint &p, QAction *action) { Q_D(QMenu); ensurePolished(); createWinId(); QEventLoop eventLoop; d->eventLoop = &eventLoop; popup(p, action); QPointer<QObject> guard = this; (void) eventLoop.exec(); if (guard.isNull()) return 0; action = d->syncAction; /// <================ action is 0 d->syncAction = 0; d->eventLoop = 0; return action; }
In QT core line: "action = d->syncAction;" action variable is 0
Any idea? -
Were else is it modified ?
-
@SGaist said in [QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.:
Were else is it modified ?
No -
Update Information:
If program start by debugger (gdb program) exec() (event loop) working correctly.
If program start without debugger exec() (event loop) immediately stop.I think:
This is XCB events. We received a event which clicking outside of the client area. And after that menu (event loop stoped) is closed.What do you think ?
-
Does it also happen if you remove the call to
popup
before callingexec
? -
@SGaist said in [QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.:
Does it also happen if you remove the call to popup before calling exec ?
Yes
-
Hi
Problem is solved.Menu closed in code info Application::eventFilter( QObject* object, QEvent* event ) on event == QEvent::FocusOut.
Thanks for all.