VirtualKeyboard, Program crash when input out of range char to a QLineEdit with validator
-
wrote on 22 Oct 2021, 08:28 last edited by
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.
-
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 ? -
wrote on 25 Oct 2021, 02:23 last edited by Anima
@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.
-
wrote on 25 Oct 2021, 02:42 last edited by
-
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 ? -
Lifetime Qt Championwrote on 1 Nov 2021, 20:34 last edited by SGaist 11 Feb 2021, 20:37
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() { }
?
-
wrote on 2 Nov 2021, 02:45 last edited by
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
-
Which compiler are you using ?
-
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() { }
?
wrote on 3 Nov 2021, 00:49 last edited by Anima 11 Mar 2021, 01:49@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.
-
Might be indeed.
One last test, what happens if you use open in place of exec ?
-
wrote on 5 Nov 2021, 05:13 last edited by
@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(); }
-
Then I would say a bug report is the next step.
-
wrote on 15 Nov 2021, 09:02 last edited by
The issue is a known bug QTBUG-9304.
Unfortunately, it will not be fixed for Qt5.12. -
From the looks of the patch, you should be able to port it to 5.12 and build the module yourself with it.