Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to add " to a String
Julian last edited by Julian
Hello, I need to add "" to a String and it do not considers. For example:
QString list; list.append("CREATE TABLE IF NOT EXISTS "); list.push_back(ui->lineEdit_interseccion->text()); //this is the tabla name list.push_back("(" "a TEXT primary key," "j TEXT" ");"); ui->label->setText(list);
And with that seTex I get:
CREATE TABLE IF NOT EXISTS Soler y Sarabia (a TEXT primary key, j TEXT)
So as you can see there is not "" between ().
How can I put it?
mostefa last edited by mostefa
let's say you have :
QString tabla = "yourString";
if you want to add
"to your string you can do someting like this :
The result will be then :
The key is to have
", \ allow you actullay to escape the character
Hope this can help !
VRonin last edited by VRonin
You can either escape (i.e. add a
"or use raw string literals
"I have a \" in the Middle"
R"**(I have a " in the Middle)**"
list.append("CREATE TABLE IF NOT EXISTS "); list.push_back(ui->lineEdit_interseccion->text()); //this is the tabla name
This is a MAJOR liability to your database, see https://www.w3schools.com/sql/sql_injection.asp
Julian last edited by
Thanks! I have a problem here
QString consulta; consulta.append("CREATE TABLE IF NOT EXISTS "); consulta.push_back(ui->lineEdit_interseccion->text() ); //this it's the table name.
then I do
consulta.push_back(" ( \" a TEXT primary key, \" \"j TEXT\" \");");
and there is the problem.
@Julian You should really read about escaping characters in C/C++.
You're escaping first " in second and third line ("j TEXT"...).
You should not because it indicates the beginning of a string!
It should be:
"\"j TEXT" "\")");
The problem now is that you span your string over multiple rows in QtCreator. The new Chars in the new line need their own
"to mark them as part of the previous string.
//Correct MultiLineString QString s = "Line1 " "\"Line2\" " "Line3 " //Results in //s = Line1 "Line2" Line3