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. VirtualKeyboard, Program crash when input out of range char to a QLineEdit with validator

VirtualKeyboard, Program crash when input out of range char to a QLineEdit with validator

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 1.0k 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.
  • A Offline
    A Offline
    Anima
    wrote on last edited by
    #1

    Hello,

    I'm trying the virtual keyboard module and found some problems. Here is what I do:

    1. in the begining of main() , enable "qtvirtualkeyboard";
    qputenv("QT_IM_MODULE", "qtvirtualkeyboard");
    
    1. In the UI, I have a QLineEdit control with validator:
     m_pEditNx = new QLineEdit();
     m_pEditNx->setValidator(new QRegExpValidator(QRegExp(u8"^([0-9]|[1-9][0-9]{1,2})")));
    

    When the QLineEdit got focus, the virtual keyboard popups up and I can input digit numbers through both the virtual keyboard and the real keyboard. And when I input characters, such as "a", "b", "c", through virtual keyboard, QLineEdit refuses these characters and works fine. But when I input characters through real keyboard, the program crashes. Here is the crash stack:

      	TextInputFramework.dll!00007ffe9804dc45()	
     	TextInputFramework.dll!00007ffe9804da87()	
     	TextInputFramework.dll!00007ffe980455e1()	
     	TextInputFramework.dll!00007ffe980441b3()	
     	TextInputFramework.dll!00007ffe9804403e()	
     	TextInputFramework.dll!00007ffe97faae33()	
     	TextInputFramework.dll!00007ffe97faad2d()	
     	TextInputFramework.dll!00007ffe97fefbcc()	
     	TextInputFramework.dll!00007ffe97fbba29()	
     	msctf.dll!00007ffea28c9dc4()	
     	TextInputFramework.dll!00007ffe97fd8a78()	
     	TextInputFramework.dll!00007ffe97fab42d()	
     	TextInputFramework.dll!00007ffe98047d90()	
     	TextInputFramework.dll!00007ffe98043c76()	
     	msctf.dll!00007ffea28e2f26()	
     	msctf.dll!00007ffea293d76b()	
     	msctf.dll!00007ffea293baba()	
     	imm32.dll!00007ffea44069dd()	
     	user32.dll!00007ffea407940a()	
    >	Qt5Cored.dll!QEventDispatcherWin32::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) line 642	C++
     	qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) line 74	C++
     	Qt5Cored.dll!QEventLoop::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) line 139	C++
     	Qt5Cored.dll!QEventLoop::exec(QFlags<enum QEventLoop::ProcessEventsFlag> flags) line 225	C++
     	Qt5Cored.dll!QCoreApplication::exec() line 1389	C++
     	Qt5Guid.dll!QGuiApplication::exec() line 1785	C++
     	Qt5Widgetsd.dll!QApplication::exec() line 2859	C++
    

    I'm using vs2015+Qt5.12.10. Is this a Qt bug? Or I missed something?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Anima
      wrote on last edited by
      #2

      I write a minimul example here:
      main.cpp

      #include "QtGuiApplication1.h"
      #include <QtWidgets/QApplication>
      
      int main(int argc, char *argv[])
      {
          qputenv("QT_IM_MODULE", "qtvirtualkeyboard");
          QApplication a(argc, argv);
          QtGuiApplication1 w;
          w.show();
          return a.exec();
      }
      

      QtGuiApplication1.h

      #pragma once
      
      #include <QtWidgets/QMainWindow>
      #include <QPushButton>
      
      class QtGuiApplication1 : public QMainWindow
      {
          Q_OBJECT
      
      public:
          QtGuiApplication1(QWidget *parent = Q_NULLPTR);
      
      public slots:
          void onBtnClicked();
      
      private:
          QPushButton*    m_pBtn;
      };
      

      QtGuiApplication1.cpp

      #include "QtGuiApplication1.h"
      
      #include "MyDialog.h"
      
      QtGuiApplication1::QtGuiApplication1(QWidget *parent)
          : QMainWindow(parent)
      {
          m_pBtn = new QPushButton("Click Me");
          setCentralWidget(m_pBtn);
      
          connect(m_pBtn, SIGNAL(clicked()), this, SLOT(onBtnClicked()));
      }
      
      void QtGuiApplication1::onBtnClicked()
      {
          MyDialog dlg;
          dlg.exec();
      }
      

      MyDialog.h

      #pragma once
      
      #include <QDialog>
      #include <QLineEdit>
      
      class MyDialog : public QDialog
      {
      public:
          MyDialog();
          ~MyDialog();
      
      private:
          QLineEdit*  m_pEdit;
      };
      

      MyDialog.cpp

      #include "MyDialog.h"
      
      #include <QRegExpValidator>
      
      MyDialog::MyDialog()
      {
          m_pEdit = new QLineEdit(this);
          m_pEdit->setValidator(new QRegExpValidator(QRegExp(u8"^([0-9]|[1-9][0-9]{1,2})")));
      }
      
      MyDialog::~MyDialog()
      {
      }
      

      When I input "a" from real keyboard, the program crashes.

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

        Hi and welcome to devnet,

        Can you show the stack trace of your crash ?
        Do you have the same issue if you use a QRegularExpressionValidator ?

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

        A 1 Reply Last reply
        0
        • A Offline
          A Offline
          Anima
          wrote on last edited by Anima
          #4

          @SGaist said in VirtualKeyboard, Program crash when input out of range char to a QLineEdit with validator:

          QRegularExpressionValidator

          Thanks, SGaist.
          And Yes. I tryed QRegularExpressionValidator and QIntValidator, still got the same result:

              m_pEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(u8"^([0-9]|[1-9][0-9]{1,2})")));
          //  m_pEdit->setValidator(new QIntValidator(0, 100));
          

          And I noticed that, if I directly put the QLineEdit on MainWindow other than MyDialog, everything is OK.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anima
            wrote on last edited by
            #5

            The stack trace.

            1.png

            2.png

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi and welcome to devnet,

              Can you show the stack trace of your crash ?
              Do you have the same issue if you use a QRegularExpressionValidator ?

              A Offline
              A Offline
              Anima
              wrote on last edited by Anima
              #6

              @SGaist
              Do you have any suggestion? Thank you.

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

                What if you use the following:

                MyDialog::MyDialog(QWidget *parent):
                    QDialog(parent)
                {
                     m_pEdit = new QLineEdit(this);
                     m_pEdit->setValidator(new QRegularExpressionValidator(QRegExp(u8"^([0-9]|[1-9][0-9]{1,2})")));
                }
                 
                MyDialog::~MyDialog()
                {
                }
                

                ?

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

                A 1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  zhangqinagqiag
                  wrote on last edited by
                  #8

                  This problem also exists in 5.15.2,As long as it is a pop-up window and uses both virtual keyboard and physical keyboard, it will crash

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

                    Which compiler are you using ?

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

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      What if you use the following:

                      MyDialog::MyDialog(QWidget *parent):
                          QDialog(parent)
                      {
                           m_pEdit = new QLineEdit(this);
                           m_pEdit->setValidator(new QRegularExpressionValidator(QRegExp(u8"^([0-9]|[1-9][0-9]{1,2})")));
                      }
                       
                      MyDialog::~MyDialog()
                      {
                      }
                      

                      ?

                      A Offline
                      A Offline
                      Anima
                      wrote on last edited by Anima
                      #10

                      @SGaist
                      Thanks.
                      The issue still exists after set the parent of MyDialog.
                      The compiler I'm using is Microsoft Visual C++ compiler 14.0.
                      I also tried MinGW 8.1.0 on Windows 10, got the same issue.

                      But on Ubuntu 18.04, the same program, built by Qt5.12.10 and g++, works fine. I think it may be a platfrom specific bug.

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

                        Might be indeed.

                        One last test, what happens if you use open in place of exec ?

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

                        A 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Might be indeed.

                          One last test, what happens if you use open in place of exec ?

                          A Offline
                          A Offline
                          Anima
                          wrote on last edited by
                          #12

                          @SGaist
                          I modified the program as below, and still got the same result. Program crashed after I tapped illegal keys with physical keyboard.

                          void QtGuiApplication1::onBtnClicked()
                          {
                              MyDialog* dlg = new MyDialog(this);
                              dlg->open();
                          }
                          
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Then I would say a bug report is the next step.

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

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              Anima
                              wrote on last edited by
                              #14

                              The issue is a known bug QTBUG-9304.
                              Unfortunately, it will not be fixed for Qt5.12.

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

                                From the looks of the patch, you should be able to port it to 5.12 and build the module yourself with it.

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

                                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