binary '%': 'QString' does not define this operator
-
wrote on 11 Jun 2023, 01:59 last edited by
Hi,
I'm trying to compile the QT source code for fun and I had an error at this code:
void toString(QString &appendTo, IPv4Address address) { // reconstructing is easy // use the fast operator% that pre-calculates the size appendTo += number(address >> 24) % u'.' % number(address >> 16) % u'.' % number(address >> 8) % u'.' % number(address); }
the error is:
error C2676: binary '%': 'QString' does not define this operator or a conversion to a type acceptable to the predefined operator
I must have some mistakes as to my local dev envirionment, which file / class should I debug into?
-
wrote on 11 Jun 2023, 10:49 last edited by
I figured out that I need to define
QT_USE_QSTRINGBUILDER
during building of qt source code (https://stackoverflow.com/a/12187069/19171308)and then
operator%
is defined:template <typename A, typename B> QStringBuilder<typename QConcatenable<A>::type, typename QConcatenable<B>::type> operator%(const A &a, const B &b) { return QStringBuilder<typename QConcatenable<A>::type, typename QConcatenable<B>::type>(a, b); }
-
Hi,
I'm trying to compile the QT source code for fun and I had an error at this code:
void toString(QString &appendTo, IPv4Address address) { // reconstructing is easy // use the fast operator% that pre-calculates the size appendTo += number(address >> 24) % u'.' % number(address >> 16) % u'.' % number(address >> 8) % u'.' % number(address); }
the error is:
error C2676: binary '%': 'QString' does not define this operator or a conversion to a type acceptable to the predefined operator
I must have some mistakes as to my local dev envirionment, which file / class should I debug into?
wrote on 11 Jun 2023, 06:51 last edited by@Felix_F_
What version of Qt?
What compiler?
What compiler options and/or Qt configure options?
What file did you paste this from?I am not as expert at C++ as some here, but https://doc.qt.io/qt-6/qstring.html shows no indication that
QString
overrides the%
operator. Here it would need to be the overridden+
operator to achieve what is desired. -
@Felix_F_
What version of Qt?
What compiler?
What compiler options and/or Qt configure options?
What file did you paste this from?I am not as expert at C++ as some here, but https://doc.qt.io/qt-6/qstring.html shows no indication that
QString
overrides the%
operator. Here it would need to be the overridden+
operator to achieve what is desired.wrote on 11 Jun 2023, 10:30 last edited by@JonB branch v6.5.1
the code is actually QT's source code, see https://github.com/qt/qtbase/blob/5ea0256b07495977a1f2740f6b2d99984cf927dc/src/corelib/io/qipaddress.cpp#L97I also tried to find an operator% definition but I didn't find it.
from the comment, you can see it's '%' not '+'.
// use the fast operator% that pre-calculates the size
-
wrote on 11 Jun 2023, 10:49 last edited by
I figured out that I need to define
QT_USE_QSTRINGBUILDER
during building of qt source code (https://stackoverflow.com/a/12187069/19171308)and then
operator%
is defined:template <typename A, typename B> QStringBuilder<typename QConcatenable<A>::type, typename QConcatenable<B>::type> operator%(const A &a, const B &b) { return QStringBuilder<typename QConcatenable<A>::type, typename QConcatenable<B>::type>(a, b); }
-
-
I figured out that I need to define
QT_USE_QSTRINGBUILDER
during building of qt source code (https://stackoverflow.com/a/12187069/19171308)and then
operator%
is defined:template <typename A, typename B> QStringBuilder<typename QConcatenable<A>::type, typename QConcatenable<B>::type> operator%(const A &a, const B &b) { return QStringBuilder<typename QConcatenable<A>::type, typename QConcatenable<B>::type>(a, b); }
wrote on 11 Jun 2023, 11:27 last edited by@Felix_F_
Interesting.There's also mention of the
QT_USE_QSTRINGBUILDER
macro, which turns all+
usage into%
, provided that doesn't create problems elsewhere on your code.But FWIW still no mention of this possibly-defined
%
operator inQString
docs page. -
@Felix_F_
Interesting.There's also mention of the
QT_USE_QSTRINGBUILDER
macro, which turns all+
usage into%
, provided that doesn't create problems elsewhere on your code.But FWIW still no mention of this possibly-defined
%
operator inQString
docs page.wrote on 12 Jun 2023, 01:11 last edited by@JonB It is there "sort of": More Efficient String Construction (also in Qt 6).
The operator%() function is not part of the QString class, which may explain why it is not documented directly there.
-
@JonB It is there "sort of": More Efficient String Construction (also in Qt 6).
The operator%() function is not part of the QString class, which may explain why it is not documented directly there.
1/7