変更点Qt Concurrent

Qt 6 は、フレームワークをより効率的で使いやすくするための意識的な努力の結果です。

私たちは各リリースにおいて、すべてのパブリックAPIのバイナリとソースの互換性を維持しようと努めています。しかし、Qt をより良いフレームワークにするために避けられない変更もあります。

このトピックでは、Qt Concurrent におけるそれらの変更点をまとめ、それらを扱うためのガイダンスを提供します。

QtConcurrent::run()

QtConcurrent::run()は、可変数の引数で動作するように改良されました:

// run
template <typename T>
QFuture<T> run(Function &&f, Args &&...args)

// run with a QThreadPool argument
template <typename T>
QFuture<T> run(QThreadPool *pool, Function &&f, Args &&...args)

副作用として、f がメンバ関数へのポインタである場合、args の最初の引数は、そのメンバが定義されているオブジェクト(または参照、またはそのポインタ)でなければなりません。つまり、次のように書く代わりに

QImage image = ...;
QFuture<void> future = QtConcurrent::run(&image, &QImage::invertPixels, QImage::InvertRgba);

と書かなければならない:

QFuture<void> future = QtConcurrent::run(&QImage::invertPixels, &image, QImage::InvertRgba);

もうひとつの副作用は、QtConcurrent::run() がオーバーロードされた関数で動作しなくなることです。例えば、以下のコードはコンパイルできません:

void foo(int arg);
void foo(int arg1, int arg2);
...
QFuture<void> future = QtConcurrent::run(foo, 42);

最も簡単な回避策は、ラムダを使ってオーバーロード関数を呼び出すことだ:

QFuture<void> future = QtConcurrent::run([] { foo(42); });

あるいは、static_cast

QFuture<void> future = QtConcurrent::run(static_cast<void(*)(int)>(foo), 42);

またはqOverload

QFuture<void> future = QtConcurrent::run(qOverload<int>(foo), 42);

QtConcurrent の他のメソッドでは、動作に変更はなく、ソース互換性の破壊も発生しません。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.