Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Exception after QMessageBox opened from C++ when another full-screen QDialog opened (android)



  • Scenario: There's a full-screen custom QDialog in place, now the dialog sends a Signal to back-end causing the back-end to open-up a QMessageBox (sort of a typical situation I would say).

    Now, things go wrong with no debug-able errors from runtime environment

    W armeabi-v7a.so: QObject::setParent: Cannot set parent, new parent is in a different thread
    E DecorView: mWindow.mActivityCurrentConfig is null
    

    Code:

    void CTools::showNotification(QString title, QString msg, eNotificationType::eNotificationType eType)
    {
        QMessageBox msgBox;
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setText(title);
        msgBox.setInformativeText(msg);
        switch(eType)
        {
        case eNotificationType::success:
            msgBox.setIconPixmap(QPixmap("qrc:/success.png"));
            break;
        case eNotificationType::warning:
              msgBox.setIconPixmap(QPixmap("qrc:/warning.png"));
            break;
        case eNotificationType::notification:
              msgBox.setIconPixmap(QPixmap("qrc:/info.png"));
            break;
        }
    
        msgBox.show();
    }
    

    Then the QMessageBox does open (without the instructed icon) followed by a sequence of segmentation faults. Of course we haven't spawned any thread at all besides the main one. Ideas?


  • Qt Champions 2019

    @Vega4 said in Exception after QMessageBox opened from C++ when another full-screen QDialog opened (android):

    msgBox.show();

    Your msgBox is a local variable and show() is a non blocking call, so msgBox will disappear just after msgBox.show().
    Either allocate the dialog on the heap or use exec().



  • This post is deleted!


  • @jsulm I got to know that in fact it was not setParent(0) that fixed the issue but usage of .exec() indeed. Now that makes 100% sense, QMessageBox allocated on stack, it got deleted. Now I got into conclusions too soon on that one. It works. The icon is not set but we'll live with that for now.


Log in to reply