Uploaded image for project: 'Qt Solutions'
  1. Qt Solutions
  2. QTSOLBUG-130

Crash in QWinWidget::focusNextPrevChild(), when focusWidget() is null.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • Some Release
    • MFC Migration
    • None
    • Windows XP SP3
      Qt 4.5.2

    Description

      Qt/MFC Migration Framework
      Version 2.8

      We use QWinWidget to embed our Widget into another Windows application. In one of our use cases the Widget loses the focus. In this case the function focusWidget() of QWinWidget returns null.

      This leads to a crash in QWinWidget::focusNextPrevChild(). The first thing that function does is calling focusWidget(). The retrieved pointer is afterward used without checking. To solve this, all you have to do is checking the pointer retrieved from focusWidget.

      The following fix solved the problem for us:

       
      bool QWinWidget::focusNextPrevChild(bool next)
      {
          QWidget *curFocus = focusWidget();
          if (0 != curFocus) {
              if (!next) {
                  if (!curFocus->isWindow()) {
                      QWidget *nextFocus = curFocus->nextInFocusChain();
                      QWidget *prevFocus = 0;
                      QWidget *topLevel = 0;
                      while (nextFocus != curFocus) {
                          if (nextFocus->focusPolicy() & Qt::TabFocus) {
                              prevFocus = nextFocus;
                              topLevel = 0;
                          } else if (nextFocus->isWindow()) {
                              topLevel = nextFocus;
                          }
                          nextFocus = nextFocus->nextInFocusChain();
                      }
      
                      if (!topLevel) {
                          return QWidget::focusNextPrevChild(false);
                      }
                  }
              } else {
                  QWidget *nextFocus = curFocus;
                  while (1) {
                      nextFocus = nextFocus->nextInFocusChain();
                      if (nextFocus->isWindow())
                          break;
                      if (nextFocus->focusPolicy() & Qt::TabFocus) {
                          return QWidget::focusNextPrevChild(true);
                      }
                  }
              }
          }
      
          ::SetFocus(hParent);
      
          return true;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            marioroessel Mario Rössel
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes