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. moc.exe cannot parse double quotes in c++ raw string correctly
Forum Updated to NodeBB v4.3 + New Features

moc.exe cannot parse double quotes in c++ raw string correctly

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 301 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kagami 0
    wrote on last edited by
    #1

    I have a very simple class TestRawString that inherits from QObject and I'm running into the infamous 'undefined reference to vtable' error in the constructor and destructor of TestRawString.

    The moc build step to generate moc_TestRawString.cpp results in the following:
    TestRawString.h:0:1: note: No relevant classes found. No output generated.
    and indeed, moc_TestRawString.cpp is an empty file.

    Once I comment the variable "raw_double_quotes" in TestRawString.h, the project will compile and run correctly. Is it a feature or something?

    This phenomenon is easy to reproduce and here are my example codes.

    TestRawString.h

    #include <QObject>
    class TestRawString : public QObject
    {
        Q_OBJECT
    public:
        explicit TestRawString(QObject *parent = nullptr);
        std::string raw_double_quotes = R"++(")++";
        std::string raw_single_quote = R"++(')++";
        std::string normal_double_quotes = "\"";
    };
    
    

    TestRawString.cpp (generated by Qt)

    #include "TestRawString.h"
    
    TestRawString::TestRawString(QObject *parent)
        : QObject{parent}
    {}
    
    

    main.cpp

    #include "TestRawString.h"
    
    int main()
    {
        TestRawString trs;
        assert(trs.normal_double_quotes == R"++(")++");
        return 0;
    }
    
    

    .pro

    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    HEADERS += \
        TestRawString.h
    
    SOURCES += \
            TestRawString.cpp \
            main.cpp
    
    

    enviroment:

    Qt: (online installation)
    QMake version 3.1
    Using Qt version 6.2.4 in C:/Qt/Qt6.2/6.2.4/mingw_64/lib
    
    compiler: gcc version 11.2.0 (x86_64-posix-seh-rev3, Built by MinGW-W64 project)
    
    os: windows 10 21H2 x86_64
    
    JKSHJ 1 Reply Last reply
    0
    • K kagami 0

      I have a very simple class TestRawString that inherits from QObject and I'm running into the infamous 'undefined reference to vtable' error in the constructor and destructor of TestRawString.

      The moc build step to generate moc_TestRawString.cpp results in the following:
      TestRawString.h:0:1: note: No relevant classes found. No output generated.
      and indeed, moc_TestRawString.cpp is an empty file.

      Once I comment the variable "raw_double_quotes" in TestRawString.h, the project will compile and run correctly. Is it a feature or something?

      This phenomenon is easy to reproduce and here are my example codes.

      TestRawString.h

      #include <QObject>
      class TestRawString : public QObject
      {
          Q_OBJECT
      public:
          explicit TestRawString(QObject *parent = nullptr);
          std::string raw_double_quotes = R"++(")++";
          std::string raw_single_quote = R"++(')++";
          std::string normal_double_quotes = "\"";
      };
      
      

      TestRawString.cpp (generated by Qt)

      #include "TestRawString.h"
      
      TestRawString::TestRawString(QObject *parent)
          : QObject{parent}
      {}
      
      

      main.cpp

      #include "TestRawString.h"
      
      int main()
      {
          TestRawString trs;
          assert(trs.normal_double_quotes == R"++(")++");
          return 0;
      }
      
      

      .pro

      QT -= gui
      
      CONFIG += c++11 console
      CONFIG -= app_bundle
      
      HEADERS += \
          TestRawString.h
      
      SOURCES += \
              TestRawString.cpp \
              main.cpp
      
      

      enviroment:

      Qt: (online installation)
      QMake version 3.1
      Using Qt version 6.2.4 in C:/Qt/Qt6.2/6.2.4/mingw_64/lib
      
      compiler: gcc version 11.2.0 (x86_64-posix-seh-rev3, Built by MinGW-W64 project)
      
      os: windows 10 21H2 x86_64
      
      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @kagami-0 said in moc.exe cannot parse double quotes in c++ raw string correctly:

      Is it a feature or something?

      It's a limitation of moc.

      As a workaround, initialize the raw string in a .cpp file, or use a non-raw escaped string.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      4

      • Login

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