Important: Please read the Qt Code of Conduct -

Console settings

  • Hello, everyone.
    Can someone tell me how do I get exit(return) code and message like "Press enter to close the window" in my console application using default Qt console(qtcreator_process_stub.exe)? 927d9271-0dcf-483f-a6f2-419e0e24209b-image.png
    Like in Visual Studio, for example:

  • @Rool

    QtCreator should write that line too.

    Do you have console in your .pro file?
    (Something like CONFIG += console)

    Is the "Run in terminal" option checked in your kit / run & build settings?

  • Lifetime Qt Champion

    @Rool This "Press enter to close the window" is not printed by your application, but Visual Studio console. You can verify that if you start your app manually from cmd.exe. If you want to have this in your app you have to do it by yourself, there is no magic. Use std::cout and std::cin for that.

  • @Rool
    As @jsulm says for the messages (they are just being produced by the VS console, not your program).

    You also ask about the "exit code". I presume the Russian states your program "exited with code 0". That corresponds to your return 0 at the end of your main(). If you write a Qt program which runs another program like the one you show, or any other program, it can retrieve the exit code of that program via, say, int exitCode = QProcess::execute("someprogram.exe", QStringList()).

  • @Pl45m4
    Yes, I have CONFIG += console c++11 in my .pro file and also option "Run in terminal" is Enabled.

  • @jsulm Yeah, I know, but I was thinking is there is an option to print this as Visual Studio console does. And also I've seen it is possible in Qt console: 26c2b732-8a3d-4d17-8829-37b9d654b236-image.png
    @jsulm said in Console settings:

    @Rool This "Press enter to close the window" is not printed by your application, but Visual Studio console.

  • @JonB I'm sorry, maybe I didn't get what you want to say, but (=qtcreator_process_stub.exe it's not my custom program but the default Qt console. Yes, it's also the program, but I think I can manage it in another way.

    @JonB said in Console settings:

    If you write a Qt program which runs another program like the one you show

  • @Rool
    You are getting hung up on what VS console is doing for you. qtcreator_process_stub.exe is just VS's own wrapper for executing your Qt console application. None of this exists outside of running your program from VS. Forget about what it does.

    • If you want to output the messages you see there, do e.g. your own cout << "Message". Or cin for reading characters.

    • The only point of the "exit code" stuff you see there is if you run a sub-process from your Qt program, and you want to get its return code. (Which is how the VS console is acting in this case.) For that I showed you how to do that from a Qt program. If you don't have that situation, then the return code is of no interest.

  • @JonB

    I think, @Rool' s question is about QtCreator settings and not the program code as such.

    I can confirm:

    • Console project, with Qt in QtCreator (MinGW) -> no message.
    • Raw C++ console project, no Qt (MinGW) -> "Press <Enter>... " message

    Raw C++ pro - file

    TEMPLATE = app
    CONFIG += console c++11
    CONFIG -= app_bundle
    CONFIG -= qt
    SOURCES += \

    Qt console .pro - file

    QT -= gui
    CONFIG += c++11 console
    CONFIG -= app_bundle
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    SOURCES += \
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    Cant say, if it's the pro - file or any other Run setting...

  • @Pl45m4 said in Console settings:

    Raw C++ console project, no Qt (MinGW) -> "Press <Enter>... " message

    Created this one and still nothing

  • @Rool

    What OS, QtCreator, Qt and compiler versions are you using?

  • @Pl45m4 Windows 10, Qt Creator 4.13.2 (Community)(Basing on 5.15.1 MSVC 2019), Qt 5.15.1, tried different compilers but usually MSVC 2019 64-bit

Log in to reply