lundi 17 juillet 2017

update QT widget in c++11 thread

I'm using c++11 std::thread to make a request and response and then update QT lineedit with the response. I've read that updating QT widget from non-gui-thread is illegal. At some code, it just works fine. So I got to think that QThread can't update QT widget and c++11 thread is OK with it.

void MyWidget::on_button_clicked() {
    std::thread([this] {
        auto req = doSomeRequest();
        req.Wait();
        auto res = req.response();

        ui->lineedit->setText(res.name());
        // emit updateName(res.name());
    }).detach();
}

But another case, it gives me a segfault. Does anyone have I idea what's going on inside of QT?

PC: @     0x7f48d426bcda QFontEngineFT::loadGlyphSet()
*** SIGSEGV (@0x10) received by PID 5484 (TID 0x7f48e4f39780) from PID 16; stack trace: ***
    @     0x7f48dfde9390 (unknown)
    @     0x7f48d426bcda QFontEngineFT::loadGlyphSet()
    @     0x7f48d426bd39 QFontEngineFT::loadGlyphFor()
    @     0x7f48d426d2cf QFontEngineFT::lockedAlphaMapForGlyph()
    @     0x7f48e0a721a0 QRasterPaintEngine::drawCachedGlyphs()
    @     0x7f48e0a74a07 QRasterPaintEngine::drawTextItem()
    @     0x7f48e0a90905 (unknown)
    @     0x7f48e091e988 QTextLine::draw()
    @     0x7f48e091f79d QTextLayout::draw()
    @     0x7f48e11ce733 QWidgetLineControl::draw()
    @     0x7f48e1142e2b QLineEdit::paintEvent()
    @     0x7f48e1051b78 QWidget::event()
    @     0x7f48e11476f5 QLineEdit::event()
    @     0x7f48e100c52c QApplicationPrivate::notify_helper()
    @     0x7f48e1013220 QApplication::notify()
    @     0x7f48e0266ae0 QCoreApplication::notifyInternal2()
    @     0x7f48e104a54a QWidgetPrivate::sendPaintEvent()
    @     0x7f48e104ab5f QWidgetPrivate::drawWidget()
    @     0x7f48e104b8c4 QWidgetPrivate::paintSiblingsRecursive()
    @     0x7f48e104b71a QWidgetPrivate::paintSiblingsRecursive()
    @     0x7f48e104b71a QWidgetPrivate::paintSiblingsRecursive()
    @     0x7f48e104b71a QWidgetPrivate::paintSiblingsRecursive()
    @     0x7f48e104a702 QWidgetPrivate::drawWidget()
    @     0x7f48e104b8c4 QWidgetPrivate::paintSiblingsRecursive()
    @     0x7f48e104a702 QWidgetPrivate::drawWidget()
    @     0x7f48e104b8c4 QWidgetPrivate::paintSiblingsRecursive()
    @     0x7f48e104a702 QWidgetPrivate::drawWidget()
    @     0x7f48e101b891 (unknown)
    @     0x7f48e101baf1 (unknown)
    @     0x7f48e103ba7f QWidgetPrivate::syncBackingStore()
    @     0x7f48e1051c40 QWidget::event()
    @     0x7f48e100c52c QApplicationPrivate::notify_helper()
fish: “./aidmat ../aidmat.ini” terminated by signal SIGSEGV (Address boundary error)

Aucun commentaire:

Enregistrer un commentaire