Qt 6.1 RegExpValidator not work ??
Solved
QML and Qt Quick
-
Qt 6.1 RegExpValidator not work
QT += quick CONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
main.qml
import QtQuick 2.12 import QtQuick.Window 2.12 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") TextInput { id: hexNumber validator: RegExpValidator { regExp: /[0-9A-F]+/ } } }
conclusion
03:26:56: Запускается /home/comp/dima/qml/exper/exper ...
QQmlApplicationEngine failed to load component
qrc:/main.qml:12:20: RegExpValidator is not a type
03:26:56: /home/comp/dima/qml/exper/exper завершился с кодом 255 -
@timob256 RegExpValidator has been replaced by RegularExpressionValidator in Qt6 so it changes to:
validator: RegularExpressionValidator { regularExpression: /[0-9A-F]+/ }
Please check the TextInput docs: https://doc.qt.io/qt-6/qml-qtquick-textinput.html#validator-prop