Can't initialise variable of type QRegExp



  • Hey,

    I have a very simple question. I have the following code (it's a header file):

    #ifndef PARSER_HPP
    #define PARSER_HPP
    
    #include <QObject>
    #include <QString>
    #include <QRegExp>
    
    class Parser
    {
        Q_OBJECT
    public:
        Parser() = default;
        Parser(QString str) : searchArgument(str) {}
    
    private:
        QString searchArgument;
        QRegExp rx("(\\d+)");
    };
    
    #endif // PARSER_HPP
    

    However, on attempting to compile it, the compiler tells me that it "expected an identifier before string constant" (the QRegExp rx("(\\d+)"); part). I am kind of confused about why it doesn't work, because in the documentation it's stated that you there is a constructor of this type that takes a QString as an argument. Any ideas?


  • Lifetime Qt Champion

    Hi,

    When using initialisation in headers, you have to use the assignment operator not the constructor.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.