The Wayback Machine - https://web.archive.org/web/20240717051245/https://www.geeksforgeeks.org/how-to-print-string-literal-and-qstring-with-qdebug-in-cpp/
Open In App

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

Last Updated : 01 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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;

C++




#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;
}


Output:

This is a string literal
This is a QString


Similar Reads

How To Convert a Qstring to Hexadecimal in C++?
In CPP Qt5 has a QString class for working with strings. It is very powerful and has numerous methods, A Unicode character string is made available via the QString class. A string is kept as a 16-bit QChar. Unicode 4.0 characters are represented by one QChar each. A QString can be changed, unlike strings in many other programming languages. Now we
2 min read
Raw String Literal in C++
A Literal is a constant variable whose value does not change during the lifetime of the program. Whereas, a raw string literal is a string in which the escape characters like ' \n, \t, or \" ' of C++ are not processed. Hence, a raw string literal that starts with R"( and ends in )". The syntax for Raw string Literal: R "delimiter( raw_characters )d
2 min read
Character Literal in C++ 17: Unicode and UTF-8 Prefix
C++17 programming introduces a foundational category known as character literals, which serve the purpose of embodying a single character. Quotation marks are employed to define them, such as 'a', 'z', or '0'. But in previous versions of C++, the available selection for character literals was confined to a comparatively minor pool of ASCII characte
3 min read
Integer literal in C/C++ (Prefixes and Suffixes)
Integer literal is a type of literal for an integer whose value is directly represented in source code. For example, in the assignment statement x = 1, the string 1 is an integer literal indicating the value 1, while in the statement x = 0x10 the string 0x10 is an integer literal indicating the value 16(in decimal), which is represented by 10 in he
4 min read
ASCII NULL, ASCII 0 ('0') and Numeric literal 0
The ASCII (American Standard Code for Information Interchange) NULL and zero are represented as 0x00 and 0x30 respectively. An ASCII NULL character serves as a sentinel character of strings in C/C++. When the programmer uses '0' in his code, it will be represented as 0x30 in hex form. What will be filled in the binary integer representation in the
3 min read
Multi-Character Literal in C/C++
Character literals for C and C++ are char, string, and their Unicode and Raw type. Also, there is a multi-character literal that contains more than one c-char. A single c-char literal has type char and a multi-character literal is conditionally-supported, has type int, and has an implementation-defined value. Example: 'a' is a character literal. "a
6 min read
Print all occurrences of a string as a substring in another string
Given two strings, str1 and str2, the task is to print the indices(Consider, indices starting from 0) of the occurrence of str2 in str1. If no such index occurs, print "NONE". Examples: Input : GeeksforGeeks GeeksOutput : 0 8Input : GFG gOutput : NONEApproach 1 (Naive Approach): A simple solution is to check all substrings of a given string one by
12 min read
Find and print duplicate words in std::vector&lt;string&gt; using STL functions
Consider an array of string and find duplicate words in that array and print that duplicate words if exist.Examples: Input : { "welcome", "to", "geeks", "for", "geeks" } Output : geeks Input : { "reduce", "reuse", "recycle", "reduce", "reuse", "recycle", " recycle" } Output : recycle reduce reuse Input : { "Go", "Green" } Output : No Duplicate word
2 min read
std::string::length, std::string::capacity, std::string::size in C++ STL
Prerequisite: String in C++ String class is one of the features provided by the Standard template library to us, So it comes up with great functionality associated with it. With these Functionalities, we can perform many tasks easily. Let's see a few of the functionalities string class provides. Header File &lt;string&gt; String Functionalities The
6 min read
Queries to insert, delete one occurrence of a number and print the least and most frequent element
Given Q queries of type 1, 2, 3 and 4 as described below. Type-1: Insert a number to the list.Type-2: Delete only one occurrence of a number if exists.Type-3: Print the least frequent element, if multiple elements exist then print the greatest among them.Type-4: Print the most frequent element, if multiple elements exist then print the smallest amo
14 min read
three90RightbarBannerImg