Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use break in Qt

Use break in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by A Former User
    #1

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

    1 Reply Last reply
    0
    • thamT Offline
      thamT Offline
      tham
      wrote on last edited by
      #2

      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);

      RIVOPICOR 1 Reply Last reply
      5
      • thamT tham

        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);

        RIVOPICOR Offline
        RIVOPICOR Offline
        RIVOPICO
        wrote on last edited by RIVOPICO
        #3

        @tham thx sir

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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();
          }
          
          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved