moc.exe cannot parse double quotes in c++ raw string correctly
-
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
-
@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.