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

Crosses initialization of Additem mAdditem



  • Hi,

    I have the following code:

        QMessageBox reviewMsgBox;
        reviewMsgBox.setText ("<b><font size='16' color='green'> Is everything correct? (Choosing yes will add the Friend to the database.)</font></b>");
        reviewMsgBox.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
        int ret = reviewMsgBox.exec ();
    
        switch(ret)
        {
        case QMessageBox::Yes:
            qDebug() << "Yes was clicked!";
    		Additem mAdditem;
            mAdditem.FunctAddToDb ();
    
            break;
        case QMessageBox::No:
            qDebug() << "No was clicked!";
            break;
        }
    

    It generates the following error message:
    review.cpp:63: error: jump to case label [-fpermissive]
    case QMessageBox::No:
    ^
    review.cpp:58: error: crosses initialization of 'Additem mAdditem'
    Additem mAdditem;

    What does that mean and how can I avoid it? Thank you.


  • Qt Champions 2019

    See here for an explanation: http://stackoverflow.com/questions/11578936/getting-a-bunch-of-crosses-initialization-error
    To fix do:

    switch(ret)
        {
        case QMessageBox::Yes:
            {
                qDebug() << "Yes was clicked!";
                Additem mAdditem;
                mAdditem.FunctAddToDb ();
            }
            break;
        case QMessageBox::No:
            qDebug() << "No was clicked!";
            break;
        }
    


  • Thank you. It worked.


Log in to reply