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

Use break in Qt



  • Sorry but with Qt it's possible to use break for example when i want to close one program. Thx in advance.



  • break is use to get out from loop, not for closing program. If you want to close the program, you can call
    QApplication::quit().

    If you want to exit because some error occur, you can call QCoreApplication::exit(), because this function can return non zero return code.

    If the event loop is not running, QCoreApplication::exit() wouldn;t work, in this case you should call exit(failure_code);



  • @tham thx sir



  • As a side note, to add to @tham, if you have a GUI application like this...

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
    }
    

    ... you can exit the application by closing the MainWindow.

    So let's say you have a QPushButton (named "push_button"), then the following clicked handler will close the window and thus exit the program:

    void MainWindow::on_pushButton_clicked()
    {
        close();
    }
    

Log in to reply