Skip to content
Related Articles
Open in App
Not now

Related Articles

How to Print String Literal and Qstring With Qdebug in C++?

Improve Article
Save Article
  • Last Updated : 01 Feb, 2023
Improve Article
Save Article

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(). 

For example:

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. 

For example:

Printing a string literal 
const char* str = "Hello World!"; 
qDebug() << str; 

Printing a QString 
QString qstr = "Hello World!"; 
qDebug() << qstr;


#include <QDebug>
#include <QString>
int main() {
   // Print String Literal 
   qDebug() << "This is a string literal";
   // Print QString 
   QString str = "This is a QString";
   qDebug() << str;
   return 0;


This is a string literal
This is a QString
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!