Skip to content
  • Mysterious QMutex destroying locked mutex

    Unsolved General and Desktop qthread qmutex crash windows7
    14
    0 Votes
    14 Posts
    5k Views
    kshegunovK
    Humor me, will you? constexpr int poolSize = 16; QVector<QThread *> threadPool(poolSize); QCoreApplication * app = QCoreApplication::instance(); for (size_t i = 0; i < poolSize; i++) { QThread * thread = new QThread(app); thread->start(); QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater); } QObject::connect(app, &QCoreApplication::aboutToQuit, [threadPool] () -> void { for (QThread * thread : threadPool) { thread->quit(); thread->wait(); } }); int index = 0; for (const QString &video : videoFiles) { ThumbnailExtractor *extractor = new ThumbnailExtractor(counter, folderPath + '/' + video); extractor->moveToThread(threadPool[index++ % poolSize]); QObject::connect(extractor, &ThumbnailExtractor::finished, extractor, &QObject::deleteLater); QMetaObject::invokeMethod(extractor, &ThumbnailExtractor::generateThumbnail, Qt::QueuedConnection); } A note here: QMediaPlayer and related classes don't seem to be reentrant so you can't use them from different threads. Stick to the main one.
  • QMutexLocker - locking question

    Unsolved General and Desktop qmutex qmutexlocker
    5
    0 Votes
    5 Posts
    1k Views
    Christian EhrlicherC
    @Dariusz said in QMutexLocker - locking question: So if its already locked, then it waits? This is exactly what a mutex is build for...
  • 0 Votes
    3 Posts
    1k Views
    S
    @SGaist Thank you! Now i see bool returnValue = d->wait(time); mutex->lock(); It will wait for mutex after waking up.