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. Console Application
QtWS25 Last Chance

Console Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.5k Views
  • 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    Hi,
    i have written a small console application which I can use it in the command prompt.
    If i double click the exe file the command prompt opens and closes immediately.

    Is there a way that the command prompt do not close?

    mrjjM 1 Reply Last reply
    0
    • beeckscheB beecksche

      Hi,
      i have written a small console application which I can use it in the command prompt.
      If i double click the exe file the command prompt opens and closes immediately.

      Is there a way that the command prompt do not close?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @beecksche

      • Is there a way that the command prompt do not close?

      Yes if your app do not close. :)
      Then command prompt stays open.

      beeckscheB 1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        add char fake; std::cin >> fake; just before the return in your main() (you'll have to #include <iostream> if you don't already)

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • mrjjM mrjj

          @beecksche

          • Is there a way that the command prompt do not close?

          Yes if your app do not close. :)
          Then command prompt stays open.

          beeckscheB Offline
          beeckscheB Offline
          beecksche
          wrote on last edited by
          #4

          @mrjj

          The structure of the code is:

          int main(int argc, char *argv[])
          {
              QCoreApplication a(argc, argv);
          
              QStringList arguments = a.arguments();
          
              // check arguments
              // do stuff and return
          }
          

          I don't enter the main event loop. After checking all arguments and doing the stuff the application returns.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Add a.exec() at the end of your code in main. It shud stop

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            4
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              [I'm assuming you are on Windows] Without polluting your code, the correct way to use that .exe is:

              1. open the command prompt (cmd.exe)
              2. [optional] navigate with cd to the directory from which you want to start the program
              3. type the absolute path to your exe (use " around it to prevent failure due to spaces or other reserved chars in your path to interfere)

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              beeckscheB 1 Reply Last reply
              2
              • VRoninV VRonin

                [I'm assuming you are on Windows] Without polluting your code, the correct way to use that .exe is:

                1. open the command prompt (cmd.exe)
                2. [optional] navigate with cd to the directory from which you want to start the program
                3. type the absolute path to your exe (use " around it to prevent failure due to spaces or other reserved chars in your path to interfere)
                beeckscheB Offline
                beeckscheB Offline
                beecksche
                wrote on last edited by
                #7

                @VRonin

                You're right, thats exactly the way i use the application. But if you could skip the three steps by double clicking the .exe file, it would be very nice.

                mrjjM 1 Reply Last reply
                0
                • beeckscheB beecksche

                  @VRonin

                  You're right, thats exactly the way i use the application. But if you could skip the three steps by double clicking the .exe file, it would be very nice.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @beecksche

                  well there is also

                  cmd /k my_script.bat

                  1 Reply Last reply
                  0

                  • Login

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