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

Problem with QMessagebox with IOS.. Application becomes unresponsive



  • I have a simple implementation of a QMessagebox in the application which otherwise runs well on IOS.
    However, when I have a QMessagebox as shown here, after the dialog pop up, the application becomes unresponsive.
    This messagebox is being called from an action on the toolbar.

        QMessageBox msg;
        msg.setText(tr("Do you really want to delete the block?"));
        msg.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
        msg.setDefaultButton(QMessageBox::No);
        msg.setParent(this);
        msg.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog);
        msg.setIcon(QMessageBox::Question);
        int ret = msg.exec();
        if(ret==QMessageBox::No)
            return;
    
    

    I though the problem might be related to this bug.
    https://bugreports.qt.io/browse/QTBUG-64577?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true

    However I dont know any solution.

    I was trying to see if I can use a uialertcontroller objective C example, but i did not get the right way to do it.

    I would appreciate help to solve this problem.

    Thanks.


  • Lifetime Qt Champion

    Hi
    What Qt version are you using ?
    Also did you try Qt::QueuedConnection as mentioned.



  • @mrjj I am using Qt 5.10.1 on IOS.
    I could not understand how to implement the Qt::QueuedConnection in this case.
    I have an action which is connected to the slot auto generated by QtCreator.
    In that slot I have some code and one part of that is getting the feedback from the user regarding whether to delete the block selected or not. If Yes, then the block is selected.
    Do I need to add another connect statement linking the trigger of that action to the slot as Qt::QueuedConnection?



  • @mrjj connect(ui->actionErase_Block,&QAction::triggered,this,&RapidMainDesigner::on_actionErase_Block_triggered_1,Qt::QueuedConnection);

    I tried to override the slot connection done by default and tried to implement the connect with a QueuedConnection. However, the problem still persists.

    Any other way to do this QueuedConnection?



  • @mrjj My IOS version is 11.4.1


  • Lifetime Qt Champion

    @TheCrowKaka
    HI
    Well adding a new connection will not override the old one.
    You could use disconnect.

    However, i was more thinking of
    manually adding a new action from code and be using QueuedConnection to test
    if that actually works then.
    I read the link as he manually connected the actions and then it worked.



  • @mrjj manually adding a new action and using QueuedConnection to test also did not work.


  • Lifetime Qt Champion

    @TheCrowKaka
    Ok. it sounded like the others got it working that way. but maybe not in all cases.
    It sounds like its fixed in 5.9.4
    What Qt are you on ?



  • @mrjj I am using Qt5.10.1



  • @mrjj I dont see a solution to this problem. I was trying to solve it by creating a custom dialog box with buttons for asking user input.
    Ideally, i should have a window that is translucent and a opaque frame with buttons and a label.
    Do you think this will be feasible?


  • Lifetime Qt Champion

    @TheCrowKaka
    Would it be possible to test with 5.9.4 ?

    Well the issues seems to be related to exec()
    so a new dialog might not work better than QMessageBox
    however , its worth a shot.



  • @mrjj if I execute the dialog with exec in a static function, that seems to work.

    Invoking the dialog this way works.

        int ret = iosmsgbox::showmessagebox(tr("Do you really want to delete the block?"),QString(),tr("Yes"),tr("No"));
    

    The dialog header...

    #ifndef IOSMSGBOX_H
    #define IOSMSGBOX_H
    
    #include <QDialog>
    
    namespace Ui {
    class iosmsgbox;
    }
    
    class iosmsgbox : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit iosmsgbox(const QString &message,const QString &btn1txt,const QString &btn2txt,const QString &btn3txt,QWidget *parent = 0);
        ~iosmsgbox();
        static int showmessagebox(const QString &message,const QString &btn1txt,const QString &btn2txt,const QString &btn3txt,QWidget *parent = 0);
    
    private slots:
        void on_btn_1_clicked();
    
        void on_btn_2_clicked();
    
        void on_btn_3_clicked();
    
    private:
        Ui::iosmsgbox *ui;
        int selvalue;
    };
    
    #endif // IOSMSGBOX_H
    
    

    The dialog cpp.

    #include "iosmsgbox.h"
    #include "ui_iosmsgbox.h"
    
    iosmsgbox::iosmsgbox(const QString &message,const QString &btn1txt,const QString &btn2txt,const QString &btn3txt,QWidget *parent) :
        QDialog(parent),
        ui(new Ui::iosmsgbox)
    {
        ui->setupUi(this);
        
        selvalue=0;
        ui->btn_1->setVisible(!btn1txt.isEmpty());
        ui->btn_1->setText(btn1txt);
        ui->btn_2->setVisible(!btn2txt.isEmpty());
        ui->btn_2->setText(btn2txt);
        ui->btn_3->setVisible(!btn3txt.isEmpty());
        ui->btn_3->setText(btn3txt);
    }
    
    iosmsgbox::~iosmsgbox()
    {
        delete ui;
    }
    
    int iosmsgbox::showmessagebox(const QString &message, const QString &btn1txt, const QString &btn2txt, const QString &btn3txt, QWidget *parent)
    {
        int returnvalue;
        iosmsgbox *mymsg = new iosmsgbox(message,btn1txt,btn2txt,btn3txt,parent);
        mymsg->exec();
        returnvalue=mymsg->selvalue;
        mymsg->close();
        delete mymsg;
        return returnvalue;
    }
    
    void iosmsgbox::on_btn_1_clicked()
    {
        selvalue=1;
        this->hide();
    }
    
    void iosmsgbox::on_btn_2_clicked()
    {
        selvalue=2;
        this->hide();
    }
    
    void iosmsgbox::on_btn_3_clicked()
    {
        selvalue=3;
        this->hide();
    }
    
    

    Now I am confused on how to make the background translucent and make just the buttons housed in the frame visible properly.


  • Lifetime Qt Champion

    Ok, so its not directly related to exec().
    Good test then.
    One note. i dont think you have to new it. since exec is blocking.
    ...
    iosmsgbox mymsg(message,btn1txt,btn2txt,btn3txt,parent);
    mymsg.exec();
    returnvalue=mymsg.selvalue;
    mymsg.close();

    should work just as well.

    • background translucent

    Is the normal messagebox translucent ? or why you want this ?

    • buttons housed in the frame visible properly.
      You mean dialog is too small or why are they not ok ?


  • @mrjj
    The Transluscent background and visible frame is only about trying to give the look similar to the messagebox.
    But this workaround works for me.


Log in to reply