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
Forum Updated to NodeBB v4.3 + New Features

Console Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.5k Views 3 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.
  • B Offline
    B Offline
    beecksche
    wrote on 20 Jan 2017, 07:28 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?

    M 1 Reply Last reply 20 Jan 2017, 07:32
    0
    • B beecksche
      20 Jan 2017, 07:28

      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?

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 20 Jan 2017, 07:32 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.

      B 1 Reply Last reply 20 Jan 2017, 07:36
      1
      • V Offline
        V Offline
        VRonin
        wrote on 20 Jan 2017, 07:32 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
        • M mrjj
          20 Jan 2017, 07:32

          @beecksche

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

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

          B Offline
          B Offline
          beecksche
          wrote on 20 Jan 2017, 07:36 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
          • D Offline
            D Offline
            dheerendra
            Qt Champions 2022
            wrote on 20 Jan 2017, 07:38 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
            • V Offline
              V Offline
              VRonin
              wrote on 20 Jan 2017, 07:59 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

              B 1 Reply Last reply 20 Jan 2017, 08:03
              2
              • V VRonin
                20 Jan 2017, 07:59

                [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)
                B Offline
                B Offline
                beecksche
                wrote on 20 Jan 2017, 08:03 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.

                M 1 Reply Last reply 20 Jan 2017, 11:09
                0
                • B beecksche
                  20 Jan 2017, 08:03

                  @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.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 20 Jan 2017, 11:09 last edited by
                  #8

                  @beecksche

                  well there is also

                  cmd /k my_script.bat

                  1 Reply Last reply
                  0

                  1/8

                  20 Jan 2017, 07:28

                  • Login

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