Skip to content

fix various warnings#43

Open
dilinger wants to merge 24 commits into
TelepathyIM:masterfrom
dilinger:warnings
Open

fix various warnings#43
dilinger wants to merge 24 commits into
TelepathyIM:masterfrom
dilinger:warnings

Conversation

@dilinger

@dilinger dilinger commented Mar 26, 2026

Copy link
Copy Markdown

This is the first batch of a bunch of TelepathyQt warning fixes. These are mostly for deprecation warnings, especially for things that are dropped with Qt6. I'm testing this on debian unstable, building against Qt 5.15.17.

I specifically avoided anything that might change the API or ABI.

@dilinger dilinger force-pushed the warnings branch 2 times, most recently from c290068 to f5b9411 Compare March 31, 2026 02:05
@Kaffeine

Kaffeine commented Mar 31, 2026

Copy link
Copy Markdown
Member

Hello. I see your work, and I'll try to at least barely review and merge it.

@dilinger

Copy link
Copy Markdown
Author

Hello. I see your work, and I'll try to at least barely review and merge it.

Thank you! Just FYI, my plan is to port to Qt6. That will break the ABI, but I'm dealing with that later while I get the lower-hanging fruit.

Andres Salomon added 20 commits April 16, 2026 23:52
toList() is currently deprecated, and building TelepathyQt produces a
bunch of the following type of warnings: "'QList<T> QSet<T>::toList()
const [with T = QString]' is deprecated: Use values() instead."

The official Qt docs recommend using range constructors (eg,
QList(QSet::begin()/QSet::end())) instead of QSet::values(), but that
would require a bunch of ifEmpty() checks and #ifdef QT_VERSION since
range constructors were only added in Qt 5.14. This keeps things simple.
Silence the following warning:
'std::__cxx11::list<T> QList<T>::toStdList() const [with T = unsigned int]'
is deprecated: Use std::list<T>(list.begin(), list.end()) instead.

This shouldn't affect the ABI at all, it's in an inlined function.
Unfortunately the isEmpty() and #if QT_VERSION checks are required.
This gets rid of many 'QSet<T> QList<T>::toSet() const [..]' is deprecated'
warnings. Unfortunately, replacing QList::toSet() requires #if QT_VERSION
checks. These are the simple replacements, with QList::isEmpty() checks as
needed.

It also includes one QSet::fromList() replacement for good measure, since
it follows the same pattern.
This gets rid of a bunch more of the toSet deprecation warnings. In
particular, these replacements are grouped together because they require
temporary variables. That's so we're not unnecessarily creating extra
copies of lists. Other than that, they're also mostly straightforward
replacements - except for the TextChannel change, where we're reusing
the temp variable elsewhere first.
Here is someplace where we were previously converting from a QList to a
QSet to get rid of duplicates, and then converting back to a QList.
Instead of dealing with that hassle, we can just use
QStringList::removeDuplicates.
Continuing to replace toSet, this Feature test called toSet so many
times that it made more sense to create a makeSet() function to handle
it.
Continuing to replace toSet with range constructions. In this case it's
involving multiple QSets, so it's not as straightforward. In the
pending-captchas case the if/else block already tested if the QLists are
empty. In the pending-contacts case, we don't need to call QSet::subtract()
at all if the second QSet is empty (because A - 0 = A).
This addresses the following warnings:
QMap<K, V>& QMap<K, V>::unite(const QMap<K, V>&) [...]' is deprecated: Use
QMultiMap for maps storing multiple values with the same key.

In these cases, I'm pretty sure that the intent was always to have
unique keys (what would it even mean to have multiple properties with
the same name?). QMap::unite allows multiple keys with the same name,
while insert() will overwrite existing property values if names conflict.
We can just switch to using insert().
/telepathy-qt/TelepathyQt/feature.cpp:65:10: warning: infinite recursion detected [-Winfinite-recursion]
   65 | Feature &Feature::operator=(const Feature &other)
      |          ^~~~~~~
/telepathy-qt/TelepathyQt/feature.cpp:67:13: note: recursive call
   67 |     *this = other;
      |             ^~~~~

This is pretty clearly meant to be calling the parent class, it just
needs the proper syntax.
Fix the warning 'QTextStream& QTextStreamFunctions::hex(QTextStream&)' is
deprecated: Use Qt::hex".
The warning "'constexpr QFlags<T>::QFlags(Zero) [with Enum = ...]' is
deprecated: Use default constructor instead" is being hit because we're
passing an integer instead of enum. Since AllEvents == 0, and AllEvents
is also the default value for QEventLoop::exec argument.. we can just
drop the arg.
Older Qt had swap() with multiple different arguments; later versions
added helper functions instead of overloading functions. swapItemsAt()
is what we want to use, as swap() is now for swapping an entire list.
QDateTime(QDate&) is deprecated. Instead, we initialize it with another
QDatetime object. However, currentDateTime() includes msecs, which will
cause the later comparison test to fail.  SecsSinceEpoch does the trick.
qrand() is deprecated, and for good reason. Instead, we use
QRandomGenerator::global(), which is not only thread-safe, but also
securely preseeded.
qsnprintf() is deprecated as of Qt 6.9; a straightforward replacement.
Silence an unused variable warning. A comment below this tells us that
checking audio_fixed_properties is good enough.
This function is declared as having a TpMediaStreamType rather than
guint as an argument.
There's no need to manually call g_ptr_array_foreach() to free elements of
a GPtrArray, as there's a function callback to do that. Once the callback
is set, it is called as long as the second argument to g_ptr_array_free()
is set to TRUE. No behavior changes here.
The easiest & best way to get rid of the qrand/qsrand deprecation
warnings in TestAvatarContacts is to just completely rip out the
unnecessary code and replace it with QTemporaryDir.

In addition, this fixes a bug where the temporary directory was never
properly deleted after finishing the test. This is because
SmartDir::removeDirectory() ran too early; after the initial
directory was cleaned up, another test would use the existing
XDG_CACHE_HOME value to store a bunch of new avatar data in the temp
directory. Moving the QTemporaryDir object into the test class allows
proper cleanup, as destruction of the object (and directory deletion)
are delayed until all the tests in this file are done running.
Straightforward replacement of QLinkedList. isEmpty() becomes empty(),
front() becomes first(), append() becomes push_back(), etc.

These two headers and various Adaptor classes aren't exported outside of
TpQt, so this shouldn't have any effect on the ABI.
@dilinger dilinger force-pushed the warnings branch 3 times, most recently from 5f9ba1c to 5924938 Compare April 17, 2026 19:26
Andres Salomon added 2 commits April 23, 2026 00:17
QXmlSimpleReader is a SAX-based parser, and is deprecated in Qt5. It
goes away in Qt6, so it makes sense to switch over. This keeps the
XmlHandler class, but just has a parse() method that handles the
top-level <service> tag, with other methods to handle other elements inside
of that.

[Note that I do have a version that drops XmlHandler, which results in
less code but a larger, less readable patch. Happy to submit that
instead, if desired.]
Using nullptr for the QFlags type is deprecated with warnings/errors
like "could not convert 'nullptr' from 'std::nullptr_t' to
'Tp::MessageSendingFlags'".

There are separate places where this is a problem that may change the
ABI, but in this commit there are no ABI modifications.
This always evaluated to true, so even with newer version of Qt the
older code was still used.
The 'register' keyword doesn't really do anything any more and is going
away, and it's really annoying to see that warning message 500 times
during a build.

I'm assuming the original author of this code meant to use 'register' to
speed things up, rather than intending to use the 'volatile' keyword to
ensure the compiler didn't optimize away the tmp variable.
@dilinger dilinger mentioned this pull request Apr 24, 2026
@dilinger

Copy link
Copy Markdown
Author

Hi @Kaffeine , please let me know if there's anything I can do to help move this forward. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants