Why is using QtConcurrent::mapped in Qt 5.15.2 causing interface blocking ?

76 Views Asked by At

main.cpp

#include <QApplication>
#include <QtConcurrent/QtConcurrent>

int numTest(const int &num)
{
    QThread::msleep(5000);

    qDebug() << "numTest in thread" << QThread::currentThread();
    return num;
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QtConcurrent::run([](){
        const int count = 2000;

        QList<int> nums;
        for (int i = 0; i < count; ++i)
            nums.append(i);

        auto result = QtConcurrent::mapped(nums, numTest);
        result.waitForFinished();
    });

    BmMessageBox::information(nullptr, "tips", "There is no help document temporarily!");

    return app.exec();
}

bmmessagebox.h

#ifndef BMMESSAGEBOX_H
#define BMMESSAGEBOX_H

#include <QDialog>
#include <QIcon>

class BmMessageBox : QObject
{
    Q_OBJECT

public:
    static void information(QWidget *parent, const QString &title, const QString &text) {
        Q_UNUSED(title);
        Q_UNUSED(text);

        QDialog box(parent);
        box.setWindowIcon(QIcon(":/resources/images/test.png"));
        box.exec();
    }
};

#endif // BMMESSAGEBOX_H

resources.qrc

<RCC>
    <qresource prefix="/">
        <file>resources/images/test.png</file>
    </qresource>
</RCC>

The BmMessageBox window uses setWindowIcon(), and the icon is stored in the resource file, which always blocks here. Why?

I tried using other versions of Qt 5.12.12, but this situation did not occur. How should I solve this problem without changing the version?

0

There are 0 best solutions below