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.


  • Moderators

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.