Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't initialise variable of type QRegExp

Can't initialise variable of type QRegExp

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 468 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.
  • E Offline
    E Offline
    El3ctroGh0st
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved