[Interest] QSettings: is a group present? Crash with qWarning.
Thiago Macieira
thiago.macieira at intel.com
Fri Aug 24 08:59:16 CEST 2012
On sexta-feira, 24 de agosto de 2012 08.04.49, Sensei wrote:
> But the real problem is this: why is the documentation referring to
> bool, and not to QBool?
>
> http://qt-project.org/doc/qt-4.8/qstringlist.html#contains
>
> bool QStringList::contains ( const QString & str,
> Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
>
>
> Actually, the header refers to QBool, as you correctly point out:
>
> inline QBool contains(const QString &str, Qt::CaseSensitivity cs =
> Qt::CaseSensitive) const;
>
>
>
> So there's a "bug" in the docs... am I right?
No. It's not a bug if it's intentional.
QBool is a hidden class that is actually a bool. In most cases, you don't
realise it's there because it casts automatically to bool. The two cases that
it won't do are in ... passing and in template matching.
Qt 4 has been using QBool for 7 years and you're the first person who has come
to this error, so I don't think it's a real issue (and you probably ignored a
compiler warning).
QBool exists to mark a function that returns a boolean in Qt 4, but returned
an int in Qt 3. It exists to make sure you're not treating the return value
like it was done in Qt 3. E.g.:
QString foo("hello hello");
if (foo.contains("hello") > 1) { ... }
The above was valid in Qt 3 but in Qt 4 it should error out. If the function
returned boolean, it would compile but it would be always false.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Intel Sweden AB - Registration Number: 556189-6027
Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120824/89b609d4/attachment.sig>
More information about the Interest
mailing list