このページでは

変更点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);

もう1つの副作用として、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 の他のメソッドには動作上の変更はなく、ソース互換性の破綻も生じません。

© 2026 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.