Print debug information in QT widget form application - c++

I have widget based qt form application. Trying to print some debug info:
qInfo()<<"Txt1 \n" ;
printf("Txt2 \n" );
But nothing is printed in Application Output console.
I have added CONFIG += console to .pro file. But no console window appeared.
How to solve simple logging problem?
UPD
This also prints nothing.
qDebug()<<"Txt1 \n" ;
If I run project in console I can see information from printf("Txt2 \n" );

You should use qDebug() to print something

You should use qDebug () to print .Otherwise you can use
fprintf(stdout,"Debug test\n");

Related

C++ std::out dont print in debug window

this is a quick question.
I am building a program in C++ and have this weird problem when it comes to print some data in the output window. I don't get any data in the output window but when I set a breakpoint I can see that data is in the variable that I am trying to print. So I am going a bit loco here.
This is the line I use to print my data:
std::cout << midiNoteNumber << std::endl;
Why does nothing appear in the debugging output window?
OutputDebugString is nothing that I could get working so I solved it by doing this:
_RPT1(0, "%d\n", midiNoteNumber);

How to print my app's output on mini2440 screen in console application?

I want to print my application out put on mini2440 screen.
I used these command in my Qt console application :
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "C++ Style Debug Message";
qDebug( "C Style Debug Message" );
system("echo 'system'");
printf("printf");
// qFatal does not have a C++ style method.
qFatal( "C Style Fatal Error Message" );
return a.exec();
}
but all these code just print the statement on my terminal not on mini2440 screen. after my device boot , i see these line :
starting networking.....
starting web servers....
starting LED services....
but I want clean them from screen and show my output on my screen instead
of these lines.
like these:
Hi dear user.
how can I do that?
I used mini2440 and wrote application in Qt creator for mini2440 . ( i commented Qtopia to run my program)
thanks :)
You shall redirect output of your application to screen, normally it's going to regular output (terminal).
First, verify which tty is representing your screen, on OK6410 bard (similar to yours) it is /dev/tty0. Simple test, type on console:
echo test > /dev/tty0
and check if text is on screen. If not then try with other tty's available on your board.
Secondary, when screen tty in know, then run application and redirect output:
./myTestAppl -qws > /dev/tty0
Where tty0 shall be replaced by tty that work for you in first point. Output from application shall show on screen.
[edit]
You can also check which tty is representing screen by review board startup script and check to which tty is send mentioned text "starting networking....." etc.
Use a STL: std::cout.
qDebug() and other predefined Qt I/O streams are not designed to show any output. They are usually used for tracing / logging.

QtCreator std::cout and output pane

When I run console applications in QtCreator the output (and input - std::cout, std::cin) is done via xterm (my OS is debian). How can I make output to be shown in the QtCreator's output pane not in the xterm window?
From the Qt Creator website:
Application Output
The Application Output pane displays the status of a program when it is executed, and the debug output.
http://doc.qt.digia.com/qtcreator/creator-quick-tour.html
It does not look like the Application Output window is what you think it is.
You should use the QDebug() function for this. It's usage is pretty much the same as std::cout.
Look at the example below:
float coordinate = 3.41;
qDebug() << "Custom coordinate type:" << coordinate;
This will output, in your QtCreator's output pane:
Custom coordinate type: 3.41
Don't forget to include this statement, in your includes block:
#include <QDebug>
For more information, check this link: http://doc.qt.io/qt-5/qdebug.html

Displaying Output on the Console Issue

I am working in a MFC application which runs in both GUI mode and user can run from command prompt. In GUI mode I work fine. But in command prompt mode, I used printf() to display the error, but nothing comes in the command prompt. To solve this I got the function AttachConsole(ATTACH_PARENT_PROCESS) to display the content to the console. But the output is not sterilized i.e. if I run the application in the command line the out put will look like bellow
G:\Bin\conTest\Debug>conTest.exe
G:\Bin\conTest\Debug>This is test comment
Press any key to continue . . .
But I want the output to be like bellow
G:\Bin\conTest\Debug>conTest.exe
This is test comment
Press any key to continue . . .
G:\Bin\conTest\Debug>
Please help me to solve the problem,
Bellow is the code snippet
DWORD written;
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
out = GetStdHandle (STD_OUTPUT_HANDLE);
}
CString dump = "This is test comment\n";
WriteConsole (out, (LPCTSTR) dump, dump.GetLength(), &written, 0);
system("pause");
FreeConsole();
Maybe this fix your issue:
Go to Project>Project Properties>Linker>System and in the right pane, set SubSystems option to Console(/SUBSYSTEM:CONSOLE)
Use this string instead:
CString dump = "\n\nThis is test comment\n";

Can I see the program output in Qt-Creator?

I am writing a simple OpenGL program with Qt Creator which basically creates a QGLWidget, shows it, and runs the application loop. I usually like debugging more with diagnostic messages turned on and off by preprocessor symbols that using an actual debugger and watches etc. In Qt Creator we have a tab called Application Output, but all I see there is "Starting xxx.exe. xxx.exe exited with code 0". No output from either std::cout or std::cerr. Now I know I could start my application from cmd.exe (yes, I am using Windows, love it :P) and see the output there but I wish I could see the output directly from the IDE. Is that possible? Thanks
Usually the Application Output pane works fine. Are you sure that you would see the output from cmd.exe (have you actually tried?)? It's usually turned off for UI applications to avoid console windows from popping up. Try CONFIG += console. Also check if you see qDebug() messages in the Application Output.
simply #include <QDebug>
and then use qDebug instead of cout like
qDebug() << "you just clicked ok";
also this works
#include <QTextStream>
QTextStream out(stdout);
out << "\nHello World!\n";
adding CONFIG += console in the .pro file didn't work for me. I wonder why?
i just discovered that i've to add "endl;" for cout to work like
cout << "print this" << endl;
Alternatively, you can check the "run in console" setting in the Project->Run options. This will open a new console window and display all console output there (if CONFIG += console is used of course).
I know that this answer do not answer the original question, but since when searching for "No application output" we found this answer...
See the following answer: https://stackoverflow.com/a/26325743/808101
This only apply to qDebug() and similar functions (not direct output to stdout/stderr).
In my case, I have to set QT_ASSUME_STDERR_HAS_CONSOLE environment variable to 1 in QtCreator in order to see qDebug() messages inside "Application Output" window.
Try:
Tools -> Options
Under the "General" tab of "Environment" change the terminal entry from:
x-terminal-emulator -e
to
xterm -e