Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt 6.1 RegExpValidator not work ??
Forum Updated to NodeBB v4.3 + New Features

Qt 6.1 RegExpValidator not work ??

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.5k 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.
  • timob256T Offline
    timob256T Offline
    timob256
    wrote on last edited by
    #1

    Qt 6.1 RegExpValidator not work

    file.pro

    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

    Снимок экрана от 2021-08-05 03-26-59.png

    eyllanescE 1 Reply Last reply
    0
    • timob256T timob256

      Qt 6.1 RegExpValidator not work

      file.pro

      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

      Снимок экрана от 2021-08-05 03-26-59.png

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @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

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      3
      • timob256T Offline
        timob256T Offline
        timob256
        wrote on last edited by
        #3

        work code

        import QtQuick 2.15
        import QtQuick.Window 2.12
        
        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            TextInput {
                id: hexNumber
                validator: RegularExpressionValidator { regularExpression: /[0-9A-F]+/ }
             }
        }
        
        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