qDebug

1. qDebug

qDebug is used to output debugging information on the console , mainly in the following ways.

1. Similar to the cout function of c++

QString str=“world”;

qDebug()<<“hello “<<str<<”!”<<endl;

  • Note: here endl plays two roles:
  • a, equivalent to \n newline
  • b. Refresh the buffer and write the buffer data to the file or screen, which will affect the efficiency of the program.
  • endl is equivalent to "/n"+flush();

2. The constructor directly introduces parameters

- string concatenation

  • Example 2.1: QString str=“world!”;
  • qDebug("hello "+str);

- Similar to the format function of CString in mfc

  • int year=18;
  • qDebug("This year I am %d", year);

Note:
%a,%A reads a floating-point value (only C99 is valid)   
%c reads a character   
%d reads a decimal integer   
%i reads a decimal, octal, hexadecimal integer   
%o reads an octal integer   
% x,%X Reads a hexadecimal integer   
%s Reads a string, terminated by a space, tab or newline.   
%f,%F,%e,%E,%g,%G are used to input real numbers, which can be input in decimal form or exponential form.   
%p reads a pointer   
%u reads an unsigned decimal integer   
%n the number of equivalent characters of the value read so far   
%[] scans the set of characters   
%% reads %symbols

2. Display the console in the Qt GUI program

Displaying the console in the Qt interface program is divided into two display methods:

1. The program displays the console at startup.

2. When the program starts, only the interface is displayed, and the console is displayed through the later trigger.

1. The program displays the console at startup.

 

2. The console is not displayed when the program starts, and then it is displayed by triggering.

The program does not display the console when it starts, and there is no need to check "run in terminal" in Qt, or select "window" in the VS configuration, just add the code to open the console in the trigger slot.

#include <winodws>
void test::openTerminal()
{
    AllocConsole();//打开控制台
    freopen("CON","w",stdout);//将输出定向到控制台
}

The article is transferred from the blog garden (ImreW): qDebug - ImreW - Blog Garden

The benefits of this article, free to receive Qt development learning materials package, technical video, including (C++ language foundation, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project combat, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓↓↓↓See below↓↓Click on the bottom of the article to receive the fee↓↓ 

 

Guess you like

Origin blog.csdn.net/QtCompany/article/details/132174016