Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

cant find QLocaleData



  • I'm overloading the QValidator class and don't know where to find QLocaleData definition (according to qt source file it's there). <QLocale> or any other #include file i could think of doesn't have it .
    I need it for this line to work:

    qlonglong entered = QLocaleData::bytearrayToLongLong(buff.constData(), 10, &ok);


  • after searching more I'm not even sure there is a QLocaleData It's just in qt source files. I'll keep digging...



  • this is as far as i got to override QIntValidator, Still don't know what to do with QLocaleData::

    hpp:

    #ifndef TEST_H
    #define TEST_H
    
    #include <QValidator>
    
    class test : public QIntValidator
    {
        Q_OBJECT
        using QIntValidator::QIntValidator;
    public:
        virtual State validate(QString &, int &) const override;
        test();
    private:
        int b;
        int t;
    };
    
    #endif // TEST_H
    
    

    cpp:

    #include "test.h"
    
    test::test()
    {
    }
    
    QValidator::State test::validate(QString & input, int &) const
    {
            bool ok;
            QByteArray buff;
            qlonglong entered = QLocaleData::bytearrayToLongLong(buff.constData(), 10, &ok);
    
            if (entered >= b && entered <= t) {
                locale().toInt(input, &ok);
                return ok ? Acceptable : Invalid;
            }
    }
    
    

  • Moderators

    @nullbuil7
    you'll finde the struct in the private part of qt source files:
    qlocale_p.h

    Those can and will change without notice so use it on your own caution


  • Lifetime Qt Champion

    Why not simply calling the base implementation and doing the check afterwards?
    Apart from this you're missing a return value.


Log in to reply