0

I'm trying to use QThreadPool on a QRunnable-base class The code is the following

void Window::on_randomBtn_clicked()
{
    QString value;

    _pool.start(_randomizer);
    _pool.waitForDone();
    value = _randomizer->value();

    ui->RVal->setText(value);
    _red.setRgb(value.toInt(), 0, 0);


    _pool.start(_randomizer);
    _pool.waitForDone();
    value = _randomizer->value();

    ui->GVal->setText(value);
    _green.setRgb(0, value.toInt(), 0);
...

In the above code _pool is an instance of QThreadPool and _randomizer an instance of a class Randomizer which extends QRunnable. The run method of the Randomizer is just a oneliner producing random numbers

I can't understand why but what happens is just a SIGABRT signal received by the application after calling the second time the _pool.start(_randomizer)

I've also tried to instantiate two different Randomizer objects but the same behavior holds.

Could you help me explaining why?

  • 1
    Please provide a minimal, reproducible example to reproduce your issue. From your pieces above noone can help you. – chehrlic Jul 23 '23 at 14:54
  • 1
    Note that by default [`QRunnable::autoDelete`](https://doc.qt.io/qt-5/qrunnable.html#autoDelete) returns true, so dereferencing `_randomizer` after calling `_pool.waitForDone()` is undefined behaviour. – G.M. Jul 23 '23 at 15:12

0 Answers0