简体   繁体   中英

printf for a C (not C++) program while using Qt Creator (not using any kinf of Qt framework)

Please note this is not C++ code and I'm not developing a Qt app.

I mostly develop embedded code and someone has knocked up a neat LCD emulator so we can write quite a lot of the code independent of the target platform (which will be embedded ARM). He's given me a gcc make file and C files which I have imported into Qt creator on a Linux desktop. It can be compiled for different platforms just with some gcc options. So although it will eventually work on an STM32 for the moment I can write code on a computer. He does it on Windows, but I'm doing it on Linux.

I'd like to do some printf commands to spit some debug data out which is something I'd never normally do on embedded developments as the IDE I use has such great facilities for setting breakpoints and looking at registers.

I should say that I can compile a line like this:

printf("Selected Index is %d, Highlighted Position is %d, Index Start is %d \n",selected_index,highlight_position,index_start);

But I'm seeing no output in the Debugger Console.

If I'm using Qt creator to write GUIs on the rare occasions I want to do print out data on the fly I'll just write to a debug window.

If I want to do a printf for a bog standard C program using Qt creator, how can I get printf to spit out data to the debugger console? In fact can it be done?

I can't use the usual Qdebug facility as I am not using any sort of Qt framework. I'm simply using Qt as an IDE and debugger for ARM C code.

As written in a comment (which I wrote as a comment because I do not have QT here and so cannot check it, nor have I used in the past months, so I was not sure), there are some solutions you can try:

  • There is another window in the bar alongside with the Debugger Console, called "Application Output", where the output of QT console applications go. Maybe the printf is written there
  • Usually both streams (STDOUT and STDERR) are redirected to the appropriate window, but sometimes not. Try changing it
  • The last solution, if nothing else works, is to use a file; write to a debug file and read back what the application has to say. Not as immediate as a direct output, but better than nothing

According to your reply, printing to STDERR shows output on the application output window, so it works also for plain C. I thought that also the STDOUT stream should have been redirected to that window, though

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM