2

Problem: CLion doesn't output any console output for debugging purposes.

I'm using CLion with the MingW compiler and cmake. No matter whether I use:

std::cout << "Testing" << std::endl;

Or:

printf("Testing");

I don't see any console output.

Attempts at Resolution:

1: I've checked "Run", "Debug", "Terminal" and "Cmake". I've attempted to edit my configurations but "Debug" doesn't show up.

2: Next, I went to Settings->Build,Execution,Deployment->CMake to edit the Generation types. I added Debug and RelWithDebInfo and still to no avail.

3: I also attempted to add "-Debug" to Cmake, but I still have no output.

4: The closest thing I've received for debugging is using GDB to view variable values at break points. This only works in the "RelWithDebInfo" generation.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
SaundersB
  • 607
  • 2
  • 12
  • 25

2 Answers2

3

Solution:

I ended up figuring out what the problem was.

I'm developing a Qt GUI application within CLion on Windows. You have to specify a console for console output to print onto.

Call this Console() function early in your main for a console prompt to open up. Now, whenever you run

QDebug() << <string>; 

or

std::cout << <string> std::endl;

You'll see your debugging statements. Hope this helps somebody else out there with the same problem.

Code:

void Console()
{
    AllocConsole();
    FILE *pFileCon = NULL;
    pFileCon = freopen("CONOUT$", "w", stdout);

    COORD coordInfo;
    coordInfo.X = 130;
    coordInfo.Y = 9000;

    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coordInfo);
    SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),ENABLE_QUICK_EDIT_MODE| ENABLE_EXTENDED_FLAGS);
}

Source:

I found a solution here: [0] Console output in a Qt GUI app?

Community
  • 1
  • 1
SaundersB
  • 607
  • 2
  • 12
  • 25
1

There's a simpler solution that doesn't require adding any code. Simply add the following environment variable in your debug configuration:

QT_ASSUME_STDERR_HAS_CONSOLE=1

With this, CLion shows QDebug and QML's console.*() when started with a debugger.

Julius Bullinger
  • 1,181
  • 11
  • 29