Debian Codegraph @

docs/checks/README-qbytearray-conversion-to-c-style.md

raw symbols SCIP
1 # qbytearray-conversion-to-c-style
2
3 Warns about usage of QByteArray to `const char *` implicit conversion operator. This
4 sort of conversion is deemed dangerous given how `const char *` is a very common type.
5 This can be fixed by making the conversion explicit, e.g. by using `QByteArray::constData()`.
6
7 Note that this conversion operator can be disabled by defining the `QT_NO_CAST_FROM_BYTEARRAY`
8 macro.
9
10 #### Caveats
11 For QByteArrayLiteral this check only works for Qt6 where QByteArrayLiteral is a macro, but not
12 with Qt5 where QByteArrayLiteral is a lambda.
13
14 #### Example
15
16 void func(const char *);
17 QByteArray ba = "some text";
18 func(ba); // Bad, implicit conversion to const char *
19 func(ba.constData()); // Good, explicit conversion
20
21 func(QByteArrayLiteral("some literal")); // Bad, implicit conversion plus QByteArray allocation
22 func("some literal")); // Good, use the string literal directly
23
24 #### Fixits
25
26 This check supports a fixit to rewrite your code. See the README.md on how to enable it.