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. AllocConsole() Not posting
Forum Update on Monday, May 27th 2025

AllocConsole() Not posting

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 3.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.
  • D Offline
    D Offline
    Denis Dolzhenko
    wrote on last edited by Denis Dolzhenko
    #1

    So the situation is that my GUI posts to the allocated console perfectly when I open the application within the QT creator application, but when I try to launch the application as a separate .exe file in its own folder the console pops up but nothing gets posted.

    That's how I initialize the console (right after ui->setupui(this);) :

    FreeConsole();
    // create a separate new console window
    AllocConsole();
    // attach the new console to this application's process
    AttachConsole(GetCurrentProcessId());
    freopen("CON", "w", stdout);
    freopen("CON", "w", stderr);
    freopen("CON", "r", stdin);
    

    That's how i try posting to the console ( all of those ways work in QT creator and none of those work in the separate app)

    puts("puts");
    std::cout << "std::cout" << std::endl;
    printf("printf\n",time.wHour,time.wMinute,time.wSecond);
    
    1 Reply Last reply
    0
    • D Offline
      D Offline
      Denis Dolzhenko
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • D Offline
        D Offline
        Denis Dolzhenko
        wrote on last edited by Denis Dolzhenko
        #3

        So the console starts working randomly sometimes.

        I think the problem is attaching the console to the app. I think so because when the console works right, I can close the console window and it will close the GUI automatically. But in situations when it does not post, I close the console and the GUI stays open.

        jsulmJ 1 Reply Last reply
        0
        • D Denis Dolzhenko

          So the console starts working randomly sometimes.

          I think the problem is attaching the console to the app. I think so because when the console works right, I can close the console window and it will close the GUI automatically. But in situations when it does not post, I close the console and the GUI stays open.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Denis-Dolzhenko If you want to start your application outside of QtCreator then you need to deploy your app properly first. That means you need to crate a directory with your executable and all libs and Qt plug-ins which are used by your application.
          See http://doc.qt.io/qt-5/deployment.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • D Offline
            D Offline
            Denis Dolzhenko
            wrote on last edited by
            #5

            Here is everything I have in my final directory, all of my features worked properly except for the console thing

            0_1496318220744_upload-76742efd-bd49-4468-aa46-90396f8539ad

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi and welcome to devnet,

              The upload feature is currently broken, please follow this guide.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi and welcome to devnet,

                The upload feature is currently broken, please follow this guide.

                D Offline
                D Offline
                Denis Dolzhenko
                wrote on last edited by Denis Dolzhenko
                #7

                @SGaist Thanks, but I think that's not the problem, I figured something else out.

                So my assumption ( found it on https://stackoverflow.com/questions/432832/what-is-the-different-between-api-functions-allocconsole-and-attachconsole-1) is that console does not always attach if I launch the executable from the explorer.

                "When run from a command prompt, two message boxes containing a 1 are displayed, meaning both calls succeeded. When run from Start -> Run, the first box contains 1 and the second contains 0, meaning that only the first call succeeded. The second one fails because explorer.exe (which is the parent of a process launched from Start -> Run) doesn't have a console."

                I tested it and it works 100% of the times when I launch the app from the command prompt.

                Is there a way I can make this work without using the command prompt?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Out of curiosity, why do you need that command prompt for ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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