Main函数里面QMessageBox的exec返回0



  • @int main(int argc, char *argv[])
    {
    CustomApplication a(argc, argv);
    AppTest w;

    QMessageBox box;

    box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    box.setDefaultButton(QMessageBox::No);

    int ret = box.exec();

    if ( ret == QMessageBox::Yes )
    {
    qDebug() << "Yes clicked";
    }
    else if(ret == QMessageBox::No)
    {
    qDebug() << "No clicked";
    }
    else
    {
    qDebug() << ret << endl;
    }

    a.setActiveWindow(&w);
    return a.exec();
    }
    @
    在main函数弹出一个对话框,发现还没有点按钮,已经返回0了,如何解决?



  • 不能这么写呢。因为QApplication都没有机会运行,主循环没有启动。


Log in to reply
 

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