QString myString = "Hello World"; const char* myCharPtr = myString.constData(); // use myCharPtr in a function that requires a const char* parameter
void printString(const char* str) { cout << str << endl; } int main() { QString myString = "Goodbye"; printString(myString.constData()); return 0; }In this example, we define a function that takes a const char* parameter and prints it to the console. We then create a QString object with the value "Goodbye" and pass a pointer to the const data of the string to the printString function using the constData method. Package Library: Qt