변경 사항 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.