Skip to content

Commit

Permalink
Mark each QT_MOC_LITERAL usage with a comment
Browse files Browse the repository at this point in the history
The comment shows to which string a QT_MOC_LITERAL is pointing.

Change-Id: Ia389d750b1b1c21e2242bad6beceea4f9298ff8e
Reviewed-by: Olivier Goffart <[email protected]>
  • Loading branch information
Jędrzej Nowacki authored and The Qt Project committed Apr 15, 2014
1 parent b526e44 commit 78a1c46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tools/moc/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,12 @@ void Generator::generateCode()
{
int idx = 0;
for (int i = 0; i < strings.size(); ++i) {
if (i)
fprintf(out, ",\n");
const QByteArray &str = strings.at(i);
fprintf(out, "QT_MOC_LITERAL(%d, %d, %d)", i, idx, str.length());
if (i != strings.size() - 1)
fputc(',', out);
const QByteArray comment = str.length() > 32 ? str.left(29) + "..." : str;
fprintf(out, " // \"%s\"\n", comment.constData());
idx += str.length() + 1;
for (int j = 0; j < str.length(); ++j) {
if (str.at(j) == '\\') {
Expand Down
11 changes: 11 additions & 0 deletions tests/auto/tools/moc/tst_moc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class TestClassinfoWithEscapes: public QObject
Q_OBJECT
Q_CLASSINFO("escaped", "\"bar\"")
Q_CLASSINFO("\"escaped\"", "foo")
Q_CLASSINFO("cpp c*/omment", "f/*oo")
Q_CLASSINFO("endswith\\", "Or?\?/")
Q_CLASSINFO("newline\n inside\n", "Or \r")
public slots:
void slotWithAReallyLongName(int)
{ }
Expand Down Expand Up @@ -800,6 +803,14 @@ void tst_Moc::classinfoWithEscapes()
const QMetaObject *mobj = &TestClassinfoWithEscapes::staticMetaObject;
QCOMPARE(mobj->methodCount() - mobj->methodOffset(), 1);

QCOMPARE(mobj->classInfoCount(), 5);
QCOMPARE(mobj->classInfo(2).name(), "cpp c*/omment");
QCOMPARE(mobj->classInfo(2).value(), "f/*oo");
QCOMPARE(mobj->classInfo(3).name(), "endswith\\");
QCOMPARE(mobj->classInfo(3).value(), "Or?\?/");
QCOMPARE(mobj->classInfo(4).name(), "newline\n inside\n");
QCOMPARE(mobj->classInfo(4).value(), "Or \r");

QMetaMethod mm = mobj->method(mobj->methodOffset());
QCOMPARE(mm.methodSignature(), QByteArray("slotWithAReallyLongName(int)"));
}
Expand Down

0 comments on commit 78a1c46

Please sign in to comment.