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. [QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.

[QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.4k Views
  • 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.
  • K Offline
    K Offline
    kas_ru
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kas_ru
      wrote on last edited by kas_ru
      #13

      Hi
      Problem is solved.

      Menu closed in code info Application::eventFilter( QObject* object, QEvent* event ) on event == QEvent::FocusOut.

      Thanks for all.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi and welcome to devnet,

        Why are you calling popup and then exec ? That doesn't look really clean.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi and welcome to devnet,

          Why are you calling popup and then exec ? That doesn't look really clean.

          K Offline
          K Offline
          kas_ru
          wrote on last edited by
          #3

          @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.

          1 Reply Last reply
          0
          • mranger90M Offline
            mranger90M Offline
            mranger90
            wrote on last edited by
            #4

            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.

            K 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @kas_ru what @SGaist meant was this: http://doc.qt.io/qt-5/qmenu.html#exec - exec already shows the menu...

              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
              1
              • mranger90M mranger90

                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.

                K Offline
                K Offline
                kas_ru
                wrote on last edited by
                #6

                @mranger90 I checked, "rect" object in Debug and Release the same.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kas_ru
                  wrote on last edited by
                  #7

                  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?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    Were else is it modified ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    K 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Were else is it modified ?

                      K Offline
                      K Offline
                      kas_ru
                      wrote on last edited by
                      #9

                      @SGaist said in [QT 5.9.7][Linux X11]Different behavior QMenu on Debug and Release build.:

                      Were else is it modified ?
                      No

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kas_ru
                        wrote on last edited by
                        #10

                        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 ?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          Does it also happen if you remove the call to popup before calling exec ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          K 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Does it also happen if you remove the call to popup before calling exec ?

                            K Offline
                            K Offline
                            kas_ru
                            wrote on last edited by
                            #12

                            @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

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              kas_ru
                              wrote on last edited by kas_ru
                              #13

                              Hi
                              Problem is solved.

                              Menu closed in code info Application::eventFilter( QObject* object, QEvent* event ) on event == QEvent::FocusOut.

                              Thanks for all.

                              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