How to Print String Literal and Qstring With Qdebug in C++?
Printing string literals and QString with QDebug in C++ can be a useful tool for debugging. By printing out the contents of a string or QString, you can quickly identify any issues that may be present in your code. In this article, we’ll discuss how to print string literals and QString with QDebug in C++.
The first step is to include the header file <QDebug>. This header file provides access to the debug output stream, which is used for printing out data. Once you have included this header file, you can use the qDebug() function to print out data from a string literal or a QString object. When printing out data from a string literal, you simply need to pass it as an argument into qDebug().
qDebug("This is my string literal");
This will print “This is my string literal” to the debug output stream. You can use the qDebug() function to print both string literal and QString with QDebug.
Printing a string literal const char* str = "Hello World!"; qDebug() << str; Printing a QString QString qstr = "Hello World!"; qDebug() << qstr;
This is a string literal This is a QString
Please Login to comment...