Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11879

Input context disappears during reparenting

    XMLWordPrintable

Details

    Description

      My goal is to develop a virtual keyboard for a line edit with the help of a QInputContext. So, I wrote an input context plugin, which you find in the directory VirtualKeyboardPlugin of the attached tarball. Then, I wrote a simple app found in the directory VirtualKeyboard; PhoneNumberWidget is the class of interest.

      In the ctor of PhoneNumberWidget, I assign a virtual-keyboard input context to a line edit:
      m_edit0 = new QLineEdit;
      m_edit0->setAttribute(Qt::WA_InputMethodEnabled);
      m_edit0->setInputContext(QInputContextFactory::create("VirtualKeyboardContext", m_edit0));

      I add the widget to a grid layout
      QGridLayout *grid = new QGridLayout;
      grid->addWidget(label0, 0, 0);
      grid->addWidget(m_edit0, 0, 1);
      which I add to a vbox layout:
      QVBoxLayout *vbox = new QVBoxLayout;
      vbox->addLayout(grid);

      Finally, I set the top-level vbox layout on "this" widget:
      setLayout(vbox);

      The function setLayout() sets the input context of the line edit to 0, that is, m_edit0->inputContext() returns 0 after setLayout() and returns the right value before. The stack trace shows this:
      #0 0x00f51931 in QMetaObject::changeGuard (ptr=0x80b6a5c, o=0x0)
      at /home/stubert/Development/Qt-4.7.0/releases/src/corelib/kernel/qobject.cpp:472
      #1 0x00322424 in QPointer<QInputContext>::operator= (this=0x80b6a5c, p=0x0)
      at ../../include/QtCore/../../../releases/src/corelib/kernel/qpointer.h:68
      #2 0x003707f3 in QWidgetPrivate::setParent_sys (this=0x80b69e0, parent=0xbffff2ac, f=...)
      at /home/stubert/Development/Qt-4.7.0/releases/src/gui/kernel/qwidget_x11.cpp:1273
      #3 0x0031ad79 in QWidget::setParent (this=0x80c4108, parent=0xbffff2ac, f=...)
      at /home/stubert/Development/Qt-4.7.0/releases/src/gui/kernel/qwidget.cpp:9950
      #4 0x0031aad8 in QWidget::setParent (this=0x80c4108, parent=0xbffff2ac)
      at /home/stubert/Development/Qt-4.7.0/releases/src/gui/kernel/qwidget.cpp:9907
      #5 0x002e4b5b in QLayoutPrivate::reparentChildWidgets (this=0x80c91e0, mw=0xbffff2ac)
      at /home/stubert/Development/Qt-4.7.0/releases/src/gui/kernel/qlayout.cpp:972
      #6 0x002e4d65 in QLayoutPrivate::reparentChildWidgets (this=0x80b5f28, mw=0xbffff2ac)
      at /home/stubert/Development/Qt-4.7.0/releases/src/gui/kernel/qlayout.cpp:976
      #7 0x0031a241 in QWidget::setLayout (this=0xbffff2ac, l=0x80d2a38)
      at /home/stubert/Development/Qt-4.7.0/releases/src/gui/kernel/qwidget.cpp:9594
      #8 0x0804bb5b in PhoneNumberWidget (this=0xbffff2ac, parent=0x0) at phonenumberwidget.cpp:45
      #9 0x0804ad59 in main (argc=1, argv=0xbffff394) at main.cpp:8

      The problem is line 1273 in qwidget_x11.cpp (QWidgetPrivate::setParent_sys), where the input context ic is set to 0 (ic = 0.

      For sure, this is the wrong behaviour. Reparenting must not remove the input context that was explicitly set before.

      Moreover, this line also introduces a memory leak. The input context set earlier is never deleted (destructor of VirtualKeyboardContext is never called).

      How to build the attached example:

      • Unpack the tarball
      • cd VirtualKeyboardPlugin; qmake; make
      • cd ../VirtualKeyboard; qmake; make
      • in VirtualKeyboard run ./VirtualKeyboard

      Attachments

        1. vkbd.tgz
          4 kB
          Burkhard Stubert
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            paeglis Gatis Paeglis
            burkhard.stubert Burkhard Stubert
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes